I'm trying to understand how to encode reads on the RSP register in x86-64.
For example, I have some code like this:
.section __TEXT,__text
.global _main
_main:
push %rsp
push (%rsp)
mov %rsp, %rax
mov (%rsp), %rax
When I assemble and dump the output, it looks like this:
$ as -o thing.o thing.s && objdump -d thing.o
thing.o: file format mach-o 64-bit x86-64
Disassembly of section __TEXT,__text:
0000000000000000 <add2>:
0: 54 pushq %rsp
1: ff 34 24 pushq (%rsp)
4: 48 89 e0 movq %rsp, %rax
7: 48 8b 04 24 movq (%rsp), %rax
push (%rsp)
becomes ff 34 24
. From what I understand, 0xFF is the opcode for PUSH, and 0x34 is Mod/RM encoding. I don't understand where 0x24 is coming from though. Is this the SIB byte? How is this instruction encoded? I can't seem to follow the Intel manual well enough to figure out where this byte comes from. I see the same byte in mov (%rsp), %rax
.