pushl/popl %esp 的汇编级表示是什么? [英] What is an assembly-level representation of pushl/popl %esp?

查看:30
本文介绍了pushl/popl %esp 的汇编级表示是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解推入和弹出堆栈指针寄存器的行为.在 AT&T 中:

I'm trying to understand the behavior of pushing and popping the stack pointer register. In AT&T:

pushl %esp

popl %esp

请注意,它们将计算出的值存储回 %esp.

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

我正在独立考虑这些说明,而不是按顺序考虑.我知道存储在 %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.

对于pushl %esp(忽略FLAGS和对临时寄存器的影响):

For pushl %esp (ignoring FLAGS and the effect on the temporary register):

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

对于popl %esp:

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

这是正确的吗?如果没有,我哪里出错了?

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

推荐答案

正如 英特尔® 64 位和 IA-32 架构开发人员手册:组合卷(实际上在第 2 卷中,或 https://www.felixcloutier.com/x86/push):

As it says about push esp in Intel® 64 and IA-32 Architectures Developer's Manual: Combined Volumes (actually in vol.2, or HTML scrape at https://www.felixcloutier.com/x86/push):

PUSH ESP 指令压入 ESP 寄存器的值,因为它存在在指令执行之前.如果 PUSH 指令使用内存操作数其中ESP寄存器用于计算操作数地址,地址在 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 (https://www.felixcloutier.com/x86/pop):

POP ESP 指令在旧数据之前递增堆栈指针 (ESP)栈顶写入目的地.

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

pop 16(%esp)

如果将 ESP 寄存器用作寻址内存中目标操作数的基址寄存器,POP 指令将在对 ESP 寄存器递增后计算操作数的有效地址.

If the ESP register is used as a base register for addressing a destination operand in memory, the POP instruction computes the effective address of the operand after it increments the ESP register.

所以是的,除了修改 FLAGS 和 %edx 之外,你的伪代码是正确的.

So yes, your pseudo-code is correct except for modifying FLAGS and %edx.

这篇关于pushl/popl %esp 的汇编级表示是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆