我只是想打印数组的元素。从输出中,我可以看到循环超出了数组的分配内存。
.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这些都不管用。
提前谢谢。
发布于 2014-01-07 16:03:15
这两个指令似乎改变了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 againhttps://stackoverflow.com/questions/20971909
复制相似问题