Assembly 为什么会无限循环?
我只是想打印数组的元素。从输出中,我可以看到循环超出了数组分配的内存Assembly 为什么会无限循环?,assembly,masm,masm32,Assembly,Masm,Masm32,我只是想打印数组的元素。从输出中,我可以看到循环超出了数组分配的内存 .386 ; 386 Processor Instruction Set .model flat,stdcall option casemap:none include \masm32\include\masm32rt.inc include \masm32\include\windows.inc include \masm32\include\kernel32.inc includelib \masm32\lib
.386 ; 386 Processor Instruction Set
.model flat,stdcall
option casemap:none
include \masm32\include\masm32rt.inc
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib
.data
array DWORD 72,50,22,0
asd DWORD ?
start:
mov ecx, 4
mov edi, 0
//-- loop start--//
loop_start:
mov eax, [array + edi * 4]
push offset asd
push eax
call dwtoa
Invoke StdOut, addr asd
inc edi //incrementing edi
dec ecx // decrementing ecx
cmp ecx,0 // comparing ecx against 0
jne loop_start // if not equal loop again
//--loop end--//
invoke ExitProcess, 0
end start
这是输出 编辑:尝试在末尾添加
cmp ecx,0
je loop_end
loop_end:
Invoke ExitProcess,0
这些都不起作用
提前感谢。这两条指令似乎改变了
ecx
寄存器:
call dwtoa
Invoke StdOut, addr asd
我猜是在dwtoa
它可能返回ecx
寄存器中返回的asci数组的长度
试试这个:
loop_start:
mov eax, [array + edi * 4]
push ecx // saving ecx before call
push offset asd
push eax
call dwtoa
Invoke StdOut, addr asd
pop ecx // restore the ecx from before the calls.
inc edi //incrementing edi
dec ecx // decrementing ecx
cmp ecx,0 // comparing ecx against 0
jne loop_start // if not equal loop again
这看起来像是在循环开始和结束ECX之间碰到了ECX?你有没有试过在通话前按一下,然后在通话后按一下?你的意思是,按一下ecx,dec ecx,pop ecx,
dec
和inc
会影响ZF,这样你就可以减少与0比较的指令