C ++
ATT大会
我正在尝试理解以下两条指令的行为:
pushl %esp
和
popl %esp
请注意,它们会将计算出的值存储回%esp
。
我正在独立地考虑这些指令,而不是按顺序。我知道%esp
中存储的值始终是递增/递减之前的值,但是我如何用汇编语言表示行为?这是我到目前为止所提出的:
推送:
movl %esp, %edx 1. save value of %esp
subl $4, %esp 2. decrement stack pointer
movl %edx, (%esp) 3. store old value of %esp on top of stack
对于pop:
movl (%esp), %esp You wouldn’t need the increment portion.
这是对的吗?如果没有,我哪里错了?感谢。
答案 0 :(得分:9)
正如Intel® 64 and IA-32 Architectures Developer's Manual: Combined Volumes中所说的那样push esp
:
The PUSH ESP instruction pushes the value of the ESP register as it existed
before the instruction was executed. If a PUSH instruction uses a memory operand
in which the ESP register is used for computing the operand address, the address
of the operand is computed before the ESP register is decremented.
关于pop esp
:
The POP ESP instruction increments the stack pointer (ESP) before data at the old
top of stack is written into the destination.