Assembly 如何输出ecx寄存器而不损坏它?
在学习如何迭代命令行参数时,我希望输出如下 arg[0]:cmdlAssembly 如何输出ecx寄存器而不损坏它?,assembly,nasm,cpu-registers,Assembly,Nasm,Cpu Registers,在学习如何迭代命令行参数时,我希望输出如下 arg[0]:cmdl arg[1]:d:/test.src arg[2]:foo 在循环中,我按下eax、epb和ecx,然后输出arg值。然后弹出3个寄存器,增加ecx,清理堆栈等 我在.bss中保留了一个变量: c: resd 1 以下是我的循环结构: .do: push ebp push eax push ecx mov [c], ecx push D
arg[1]:d:/test.src
arg[2]:foo 在循环中,我按下eax、epb和ecx,然后输出arg值。然后弹出3个寄存器,增加ecx,清理堆栈等 我在.bss中保留了一个变量:
c: resd 1
以下是我的循环结构:
.do:
push ebp
push eax
push ecx
mov [c], ecx
push DWORD [ebx]
push DWORD [c]
push marg
call _printf
add esp, 8 ; clean up stack
pop ecx
pop eax
pop ebp
add ebx, 4 ; move to next arg
inc ecx ; increment counter
cmp ecx, eax
jne .do
在.data部分中,marg的定义如下:
marg: db "arg[%d]: %s", 10, 0
这是我当前的输出,应用程序将终止:
arg[0]:cmdlarg[7020225]:d:/test.src
arg[7019969]:foo
arg[7019929]:(空)
您没有正确平衡堆栈:
push DWORD [ebx]
push DWORD [c]
push marg
...
add esp, 8 <-- This is wrong
推送DWORD[ebx]
推送DWORD[c]
推边
...
添加esp,8您没有正确平衡堆栈:
push DWORD [ebx]
push DWORD [c]
push marg
...
add esp, 8 <-- This is wrong
推送DWORD[ebx]
推送DWORD[c]
推边
...
添加esp,8