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:
leaq (%rsp, %rdx), %rax
However, I am failing to understand using a suffix for pop
. For example, using the same logic, it would make sense to me that we'd use popl
for something like:
popl %edi
But, in the text and other examples online, I just see:
pop %edi
What is the difference? is popl
even valid? 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. 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? 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.
That's why your assembler won't accept pop %edi
or popl %edi
. Those are exactly equivalent because the 32-bit register implies DWORD ( l
) operand-size. 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.
You only need a size suffix when it's ambiguous, mov $1, (%rdi)
. Your assembler will give an error for that instead of guessing one of 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. How many bytes does the push instruction push onto the stack when I don't specify the operand size?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.