What is an assembly-level representation of pushl/popl %esp?

做~自己de王妃 提交于 2019-12-29 07:39:09

问题


C++

ATT Assembly

I'm trying to understand the behavior of the following two instructions:

pushl %esp

And:

popl %esp

Note that they store the computed value back into %esp.

I'm considering these instructions independently, not in sequence. I know that the value stored in %esp is always the value before the increment/decrement, but how could I represent the behavior in assembly language? This is what I've come up with so far:

For push:

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

For pop:

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

Is this correct? If not, where am I going wrong? Thanks.


回答1:


As it says about push esp in 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.

And as regards to pop esp:

The POP ESP instruction increments the stack pointer (ESP) before data at the old
top of stack is written into the destination.


来源:https://stackoverflow.com/questions/14968824/what-is-an-assembly-level-representation-of-pushl-popl-esp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!