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

问题描述 投票:6回答:1

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. 

它是否正确?如果没有,我哪里错了?谢谢。

assembly x86 stack att
1个回答
9
投票

正如它在push esp中所说的Intel® 64 and IA-32 Architectures Developer's Manual: Combined Volumes

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.
© www.soinside.com 2019 - 2024. All rights reserved.