什么是pushl / popl%esp的汇编级表示?

时间:2013-02-19 22:30:10

标签: assembly x86 stack att

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. 

这是对的吗?如果没有,我哪里错了?感谢。

1 个答案:

答案 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.