CMU 15-213 [1]

Last

x86-64 registers

x86 registers

Archeology Name Layer

  • One register can have four identities: RAX -> EAX -> AX -> AL. EAX is the lower byte of RAX, AX is the lower byte of EAX and AL is still the lowest 8 bytes.

    [!NOTE]
    Writing the lower 32 bits of a register would clear the higher 32 bits of it.(mov eax, 1 would clear the higher 32 bits of rax)

  • 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, R9 in 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 -> RDI
      • b -> RSI
      • c -> RDX
      • d -> RCX
      • e -> R8
      • f -> R9
  • 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, use RAX + 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, R11 are caller-saved.
    • Registers RBX, RBP, R12, R13, R14, R15 are callee-saved.

Stack Address Alignment

  • For historical and performance reason, it is required that the address stored in RSP is 16-byte aligned. However, the caller would push the return address on the stack when calling, so situation becomes %rsp % 16 == 8 when 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, R9 in 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, use RAX + 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.
Comments