NOTE
Registers
Study notes on x86-64 registers, including general-purpose registers, RIP, segment registers, and stack-related registers.
This is a historical learning note and may contain outdated or incomplete understanding.
1. What Is a Register?
A storage unit inside the CPU. Used to hold data read from memory (including instructions) and intermediate results of CPU operations. Cache
2. Why Are Registers Needed?
The CPU reads and writes registers much faster than it reads and writes memory.
3. Register Categories
CPUs with different architectures have different numbers, types, and names of internal registers. AMD64 is used here as an example.
3.1. General-Purpose Registers
rax,rbx,rcx,rdx,rsi,rdi,rbp,rsp,r8,r9,r10,r11,r12,r13,r14, andr15rspandrbpare both related to the function call stack.rspis generally used as the stack pointer.- When a frame pointer is used,
rbpis commonly used as a reference point for the function’s stack frame. - For an example, see Process
- Mainly used to temporarily hold data.
- 64 bit; lower-width 32/16/8-bit register names can also be used.

3.2. Program Counter Register (PC Register)
rip- Holds the instruction pointer, i.e. the address of the next instruction to execute.
- 64 bit
3.3. Segment Registers
fsandgs- On x86-64 systems, operating systems commonly use them for facilities such as thread-local storage (TLS).
- The FS/GS segment selectors themselves are 16 bit; on x86-64, the FS/GS base used for address calculation can be 64 bit.
Discussion
Sign in with GitHub to comment. Discussions are stored as GitHub Issues.View on GitHub