简体   繁体   English

了解汇编中的弹出指令

[英]Understanding the pop instruction in assembly

I am a student studying computer systems for the first time (w/ Computer Systems: A Programmer's Perspective). 我是一名初次学习计算机系统的学生(带有计算机系统:程序员的观点)。 We are working on assembly and I am starting to understand command suffixes for x86_64 such as using leaq in something like: 我们正在组装,我开始了解x86_64的命令后缀,例如在以下代码中使用leaq

leaq (%rsp, %rdx), %rax

However, I am failing to understand using a suffix for pop . 但是,我无法理解使用pop的后缀。 For example, using the same logic, it would make sense to me that we'd use popl for something like: 例如,使用相同的逻辑,对于我来说,将popl用于类似的事情对我来说很有意义:

popl %edi

But, in the text and other examples online, I just see: 但是,在网上的文字和其他示例中,我只看到:

pop %edi

What is the difference? 有什么区别? is popl even valid? popl甚至有效吗? Just looking for a little more insight. 只是寻找更多的见识。 Anything helps, thank you. 有什么帮助,谢谢。

What you can do in asm is limited by what the hardware can do. 在asm中可以执行的操作受硬件可以执行的操作的限制。 Implicit vs. explicit operand-size in the source (suffix or not) doesn't change the machine code it will assemble to. 源代码中隐式或显式操作数的大小(带或不带后缀)不会更改将要汇编到的机器代码。

So the right question to ask is whether the hardware can do a 32-bit push in 64-bit mode? 因此,正确的问题是硬件是否可以在64位模式下进行32位推送? No, it can't, therefore no asm source syntax exists that will get it to do exactly what you were trying to do with one instruction. 不,它不能,因此不存在任何asm源语法,可以使它完全执行您试图用一条指令执行的操作。

That's why your assembler won't accept pop %edi or popl %edi . 这就是为什么您的汇编器不接受pop %edipopl %edi Those are exactly equivalent because the 32-bit register implies DWORD ( l ) operand-size. 它们完全等效,因为32位寄存器隐含了DWORD( l )操作数大小。 The examples you saw of popl or pop %edi are for 32-bit mode, where EDI is the full register instead of the low half of RDI, and that instruction is encodable. 您看到的poplpop %edi的示例适用于32位模式,其中EDI是完整寄存器,而不是RDI的低半部分,并且该指令是可编码的。

You only need a size suffix when it's ambiguous, mov $1, (%rdi) . 仅在模棱两可时才需要大小后缀, mov $1, (%rdi) Your assembler will give an error for that instead of guessing one of b/w/l/q. 您的汇编器将为此给出错误,而不是猜测b / w / l / q中的一个。

But push is a bit special: push $1 will default to a 64-bit push, even though pushw $1 is possible. 但是push有点特殊: push $1将默认为64位push,即使pushw $1是可能的。 How many bytes does the push instruction push onto the stack when I don't specify the operand size? 当我未指定操作数大小时,push指令会将多少个字节推入堆栈?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM