我不記得MASM32使用確切的指令,但基本結構應該是這樣的:
mov edi, addr tiles ; might be called offset, some assemblers (notably gas) would use something like lea edi, [tiles] instead
mov ecx, 12 ; the count, this could be gotten from an equ, read from a variable etc.
for_loop:
add byte ptr [edi], 2 ; tiles[i] += 2
inc edi ; move to next tile
dec ecx ; count--
jnz for_loop ; if (count != 0) goto for_loop
或者,如果你希望它是結構更像是C#代碼:
mov edi, addr tiles
sub ecx, ecx ; ecx = 0
for_loop:
cmp ecx, 12 ; ecx < tiles.Length ?
jnl done ; jump not less
add byte ptr [edi+ecx], 2 ; tiles[i] += 2
inc ecx ; i++
jmp for_loop
done:
請注意,如果更改tiles
的類型,則某些代碼將不得不更改(特別是涉及edi
的代碼)。