什么是pushl / popl等ESP%的组件级表示?(What is an assembly-le

2019-07-20 04:24发布

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

对于流行:

movl (%esp), %esp   You wouldn’t need the increment portion. 

它是否正确? 如果不是这样,我要去哪里错了? 谢谢。

Answer 1:

因为它说,大约push esp在英特尔®64和IA-32架构开发人员手册:综合卷 :

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.


文章来源: What is an assembly-level representation of pushl/popl %esp?