更新(2017-11-13):MASM配列がループしない
別の変数「index」を追加してゼロに設定しました。その後、すべての.IFループの後で、インデックスに4(DWORD)を追加し、esiレジスタに渡して、正しい配列変数を指しています。私はincludedCounter変数を.IFループの外に移動しました。答えは正しかった!!
Iは= 8> = 3 & & <ある値のみが配列へのポインタ[ESI]のみ配列の最初の値に「ループ」される配列との和をループしようとしています( 3)。
ESIが次の配列にインクリメントしないのはなぜですか?
値は、合計の "64"とincludedCounterの "13"を返します。現在の値は、sumの場合は「60」、includedCounterの場合は「20」として返されます。これは、配列内の各整数が指すのではなく、配列の最初の整数が常に指し示されていることを示しています。
; Calculates the sum of all array elements
; >= "lower" value (3) and <= "higher" value (8).
INCLUDE Irvine32.inc
.data
sum DWORD ? ; EAX - holds sum of included integers
lower DWORD 3 ; holds lower value
upper DWORD 8 ; holds higher value
;Update (2017-11-13)
index DWORD 0 ; holds index for array
;==============
loopCounter DWORD ? ; ESI - holds loop array pointer
includedCounter DWORD ? ; EDX - holds 'included' counter
array DWORD 3,1,4,1,5,9,2,6,5,3,5,8,9,7,9,3,2,3,8,4 ; values checked
arraySize = ($ - array)/TYPE array ; [current location lounter ($) - array/DWORD] = 20
.code
main PROC
mov eax, sum
mov ebx, lower
mov ecx, upper
mov edx, includedCounter
.WHILE loopCounter < arraySize ; While loopCounter is less than 20
;Update (2017-11-13)
mov esi, index
;===============
.IF (array[esi] >= ebx) && (array[esi] <= ecx)
add eax, array[esi]
inc includedCounter
.ENDIF
;Update (2017-11-13)
add index, 4
inc loopCounter
;================
.ENDW
; Display values
mov sum, eax
mov eax, sum
call WriteInt
call CrLF
mov eax, includedCounter
call WriteInt
Call CrLF
; Exit program
call WaitMsg
exit
main ENDP
END main
あなたのコードのどの部分が 'ESI'をインクリメントするべきだと思いますか? –
ESIが配列の値を指すように配列に追加されている場合は、配列の次の値を指し示すためにESIをインクリメントする必要がありますか? – Robert