【发布时间】:2018-02-11 13:59:15
【问题描述】:
任何人都可以用堆栈解释我的代码吗?下面给出的代码应该是用于打印命令行参数,然后向它添加 1 并再次打印它。 但是由于在这种情况下堆栈工作,我完全感到困惑。 而且我认为代码中有一些错误。
SECTION .data
msg:db"You Entered -%s", 10, 0; print argv[1] data
msg2:db"This is int-%d", 10, 0; print INT equivalent
SECTION .text
extern printf
extern atoi
global main
main:
; set-up phase
push ebp
mov ebp, esp
; get the command-line data
mov ebx, DWORD [esp+ 12] ; get argvstarting address
mov ebx, [ebx+ 4] ; get the second argument data
; print the value
push ebx ; put data on stack for call
push msg ; print the value
call printf
; convert to integer
add esp, 4 ; stack points to entry edx
call atoi ; call atoi-return in EAX?
; get return value and add 1
add esp, 4 ; esppoints to start
inc eax ; increase eaxfor testing
; print the result
push eax ; push argfor print
push msg2 ; push print message
call printf
; finish phase
add esp, 8 ; esp back to start
movesp, ebp
pop ebp
ret
【问题讨论】: