x86 Registers
x86 Architecture Deep Dive · CPU Architectures track
5 min read
In this module
A Named Register Set
Where our teaching ISA gives you tidy R0-R7, x86 hands you a lineup of named registers carrying forty years of historical baggage. You'll meet them constantly when reading assembly, writing exploits, or chasing down a calling convention.
General-Purpose Registers
In 64-bit mode (x86-64), there are 16 general-purpose registers. The original eight have a naming convention rooted in their historical roles:
| 64-bit | 32-bit | 16-bit | High 8 | Low 8 | Original Purpose |
|---|---|---|---|---|---|
| RAX | EAX | AX | AH | AL | Accumulator |
| RBX | EBX | BX | BH | BL | Base |
| RCX | ECX | CX | CH | CL | Counter |
| RDX | EDX | DX | DH | DL | Data |
| RSI | ESI | SI | - | SIL | Source Index |
| RDI | EDI | DI | - | DIL | Destination Index |
| RSP | ESP | SP | - | SPL | Stack Pointer |
| RBP | EBP | BP | - | BPL | Base Pointer |
x86-64 added eight more: R8 through R15 (with sub-registers R8D, R8W, R8B, etc.).
Each of the original registers can be accessed at different widths. AL is the low byte (bits 0-7), AH is the next byte (bits 8-15), AX is the low 16 bits, EAX is the low 32 bits, and RAX is the full 64 bits. Writing to EAX zero-extends into RAX. Writing to AX or AL does not zero-extend - it only modifies the targeted bits.
The low bytes SPL, BPL, SIL and DIL (and R8B-R15B) only exist in 64-bit mode and need a REX prefix to encode. Using that prefix changes what the old byte-register codes mean, so a single instruction can't mix AH, BH, CH or DH with any of them.
Worked Example: Four Writes to One Register
The zero-extension rule sounds like trivia until it changes a value under your nose. Start with rax holding 0x1122334455667788 and apply each write in turn:
| Instruction | rax afterwards | What changed |
|---|---|---|
mov al, 0xff | 0x11223344556677ff | Only the lowest byte |
mov ah, 0xee | 0x112233445566eeff | Only bits 8-15 |
mov ax, 0x1234 | 0x1122334455661234 | Only the low 16 bits |
mov eax, 1 | 0x0000000000000001 | The low 32 bits, and the top 32 are cleared |
The first three writes leave everything above them untouched, which is how the 16-bit and 8-bit registers always behaved. The 32-bit write is different. AMD made it zero the upper half when they designed x86-64, so that 32-bit code wouldn't drag stale high bits around and wouldn't need to wait for the old value of the full register before writing.
That rule is why compilers love 32-bit forms. xor eax, eax (2 bytes, 31 c0) clears all of rax, and it's the standard way to zero a register. You'll see it everywhere, often before a call or a ret.
Predict: mov rax, -1 then mov ax, 0. What's in rax?
0xffffffffffff0000. mov rax, -1 fills all 64 bits with ones. The 16-bit write replaces only the bottom 16 bits with zeros and leaves the other 48 bits set. Had the second instruction been mov eax, 0, the answer would be plain 0.
Here's rax with the same starting value. Press the four mov buttons in order and watch the outlined bits: the first three writes stay inside their own lane, while mov eax, 1 wipes the top 32 bits as well. The table underneath reads each sub-register out of the same 64 bits. Try mov rax, -1 followed by mov ax, 0 to check your answer to the question above.
| Field | Bits | Hex | Decimal |
|---|---|---|---|
| EAX | 31-0 | 0x55667788 | 1432778632 |
| AX | 15-0 | 0x7788 | 30600 |
| AH | 15-8 | 0x77 | 119 |
| AL | 7-0 | 0x88 | 136 |
Special-Purpose Registers
A handful of registers carry fixed architectural duties:
- RSP (Stack Pointer) - points to the top of the current stack frame. PUSH and POP modify this automatically.
- RBP (Base Pointer) - traditionally points to the base of the current stack frame, making local variables and function arguments reachable at fixed offsets.
- RIP (Instruction Pointer) - holds the address of the next instruction to execute. You can't write to RIP directly with MOV, but jumps and calls modify it.
- RFLAGS - status bits set by arithmetic and comparison instructions. The ones you'll actually care about are ZF (zero), SF (sign), CF (carry), and OF (overflow). Conditional jumps read these flags.
cmp is where the flags earn their keep. cmp rax, rbx subtracts rbx from rax, throws the answer away and keeps only the flags. A following je jumps if ZF is set (the values were equal), jl checks SF and OF for a signed less-than, and jb checks CF for an unsigned below. Same comparison, different jump, different meaning, which is exactly where signed and unsigned bugs hide.
Load the 0xff vs 1 preset below: in 8 bits that byte is 255 to ja and -1 to jl, and both jumps fire. Then try INT_MIN - 1 to watch OF rescue jl after the result wraps, and switch to the drill to predict ZF, SF, CF and OF yourself before they're revealed.
cmp, test and the flags
Presets
cmp al, bl ; a - b, result thrown away
- ZF: the result is zero.
- SF: the result's top bit (bit 7) is set.
- CF: unsigned a is below unsigned b, so the subtraction borrowed.
- OF: the signed answer doesn't fit in 8 bits, so the result's sign is wrong.
| Jump | After cmp a, b | Reads | Taken |
|---|---|---|---|
| Equality | |||
| je / jz | a == b | ZF=1 | Not taken |
| jne / jnz | a != b | ZF=0 | Taken |
| Signed | |||
| jl / jnge | a < b | SF≠OF | Taken |
| jge / jnl | a >= b | SF=OF | Not taken |
| jle / jng | a <= b | ZF=1 or SF≠OF | Taken |
| jg / jnle | a > b | ZF=0 and SF=OF | Not taken |
| Unsigned | |||
| jb / jc | a < b | CF=1 | Not taken |
| jae / jnc | a >= b | CF=0 | Taken |
| jbe / jna | a <= b | CF=1 or ZF=1 | Not taken |
| ja / jnbe | a > b | CF=0 and ZF=0 | Taken |
Segment Registers
x86 still drags six segment registers around from the 16-bit era: CS, DS, SS, ES, FS, and GS. They were core machinery in the original 8086's segmented memory model. In 64-bit mode most are vestigial, though operating systems repurpose FS and GS for thread-local storage and kernel data structures. On Linux, fs:0x28 is where each thread keeps its stack canary, which you'll meet in Exploit Mitigations.
SIMD Registers
Modern x86 processors include additional register sets for SIMD (Single Instruction, Multiple Data) operations:
- XMM0-XMM15 - 128-bit registers for SSE operations.
- YMM0-YMM15 - 256-bit registers for AVX (the XMM registers are the lower half).
- ZMM0-ZMM31 - 512-bit registers for AVX-512.
These are used for floating-point maths, vector processing, and cryptographic operations.
Comparing to Our Teaching ISA
Our teaching ISA gives you eight registers (R0-R7), all identical and freely interchangeable. x86 has 16 in 64-bit mode, wider at 64 bits, and many of them carry implicit roles you have to remember. The whole register set reads like an archaeological dig — each layer added by a different generation of extension.