【发布时间】:2016-11-02 22:48:30
【问题描述】:
嘿,我需要编写一个循环遍历数组 (1,2,3,4,5,6,7,8,9,10) 并将元素“i”与元素“i+5”交换的程序当 'i' 小于 4 程序结束时,新数组有以下值 6,7,8,9,10,1,2,3,4,5
现在我让它在数组中循环
.386
.model flat,stdcall
.stack 4096
ExitProcess proto,dwExitCode:dword
WriteDec PROTO
Crlf PROTO
DumpRegs PROTO
.data
arrayB WORD 1,2,3,4,5,6,7,8,9,10
.code
main proc
mov eax,0
mov edi,OFFSET arrayB ; address of arrayB
mov ecx,LENGTHOF arrayB ; loop counter
mov ax,0 ; zero the accumulator
L1:
mov ax,[edi] ; mov current edi value from array into ax
xchg arrayB, ax ;change the current ax register with the value in arrayB
add edi,TYPE arrayB ; point to next integer
loop L1
call DumpRegs
call WriteDec
call crlf
invoke ExitProcess,0
main endp
end main
但我实际上遇到了麻烦 a) 告诉循环何时低于 4,b) 正确替换值。任何帮助将不胜感激
编辑:我知道我可以使用“cmp”来比较 ecx 寄存器
【问题讨论】:
-
你的问题有新答案了,看看吧!