惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
B
Blog
M
MIT News - Artificial intelligence
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
P
Proofpoint News Feed
C
Check Point Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
J
Java Code Geeks
博客园 - 叶小钗
S
SegmentFault 最新的问题
Last Week in AI
Last Week in AI
T
The Blog of Author Tim Ferriss
Microsoft Security Blog
Microsoft Security Blog
小众软件
小众软件
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 【当耐特】
腾讯CDC
博客园 - Franky
博客园 - 聂微东
V
Visual Studio Blog
GbyAI
GbyAI
Martin Fowler
Martin Fowler
罗磊的独立博客
Y
Y Combinator Blog

Last Blog

CMU 15-213 Attack Lab GAMES101 [1] Affine Transformation & Projection CMU 15-213 Bomblab Scribe.cx 2 - 对话与持久化存储 关于 X11 与 Wayland 的剪贴板同步问题 关于 X11 与 Wayland 的剪贴板同步问题 Scribe.cx 1 - 跨浏览器的插件侧板控制 Page Assist 2025 年终总结 2025 年终总结 Linuxqq 粘贴板同步问题 关于所谓“配置工程师” 记一次小端序内存的实际体现 CS110L L3 - Memory Safety in Rust CS110L L2 - Program Analysis CS110L L1 - Safety in System Programming 在 Neovim(v0.10+) 上使用 arduino-language-server PA3 - Batch Processing System 2024 年终总结 Arcaea 曲名匹配器 Arcaea 曲名匹配器 PA W9 - Linking & Loading Hyprland 二周目 Hyprland 二周目 PA2 Part 2 - Emulated Hardware Device PA W8 - IO Devices Learn C the Hard Way PA2 Part 1 - Instruction Set Implementation & KLIB Learning Makefile with PA 阅读 MQTTX 项目:Protobuf Test Case
CMU 15-213 [1]
Last · 2026-07-13 · via Last Blog

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.