【发布时间】:2015-04-17 06:04:03
【问题描述】:
学习如何迭代命令行参数,我想这样输出
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 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]: cmdl
arg[7020225]: d:/test.src
arg[7019969]: foo
arg[7019929]: (null)
【问题讨论】:
标签: assembly nasm cpu-registers