CMU 15-213 [1]
x86-64 registers

Archeology Name Layer
One register can have four identities:
RAX->EAX->AX->AL.EAXis the lower byte ofRAX,AXis the lower byte ofEAXandALis still the lowest 8 bytes.[!NOTE]
Writing the lower 32 bits of a register would clear the higher 32 bits of it.(mov eax, 1would clear the higher 32 bits ofrax)This is due to Intel’s backward compatability decision, making it impossible to change the names of the registers in their cpu. As a result, they could only extend the names of these registers while reserving the old ones.
Special Regsiters
- There are some registers with special purposes:
RSP, representing stack pointer, points to the top of the current stack.RBP, representing base pointer, is used for creating stack frame.(Not common for modern compilers)RIP, representing instruction pointer, stores the address of the instruction to be executed next.
Calling Convention
Linux/MacOS: System V AMD64 ABI
For a standard function call, 6 of its parameters goes into
RDI, RSI, RDX, RCX, R8, R9in order.- For example, when calling function
long f(long a, long b, long c, long d, long e, long f);, the corresponding register for each of the parameters is:a->RDIb->RSIc->RDXd->RCXe->R8f->R9
- For example, when calling function
Parameters after the sixth goes to the stack.
[!NOTE]
Floating point parameters have their own special registers.
- Return values are usually stored in
RAX. If it’s too big to be stored inside one register, useRAX + RDX.
Caller-saved & Callee-saved
Sometimes the execution of a funcion might overwrite the value in other registers set by the caller, though the values inside them might still be required for subsequent process. There are two conventions to resolve this problem.
- Caller-saved: The caller of the function should save the values which are required after the function call on its own.
- Callee-saved: The funcion that is called should restore the values of the ones it overwrites before return.
In System V AMD64 ABI:
- Registers
RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11are caller-saved. - Registers
RBX, RBP, R12, R13, R14, R15are callee-saved.
- Registers
Stack Address Alignment
- For historical and performance reason, it is required that the address stored in
RSPis 16-byte aligned. However, the caller would push the return address on the stack when calling, so situation becomes%rsp % 16 == 8when the callee arrives.
Windows x64: Microsoft x64 calling convention (Optional)
Similiar to System V AMD64 ABI, puting the first four parameters to
RCX, RDX, R8, R9in order while the rest goes on to the stack.Return values are usually stored in
RAX. If it’s too big to be stored inside one register, useRAX + RDX.
- Title: CMU 15-213 [1]
- Author: Last
- Created at : 2026-07-13 09:12:22
- Link: https://blog.imlast.top/2026/07/13/cmu15213-1/
- License: This work is licensed under CC BY-NC-SA 4.0.