x86-64 Architecture Guide — CPU Modes, Registers, and Instruction Set
In this tutorial, you will learn about x86. We cover key concepts, practical examples, and best practices to help you master this topic.
x86-64 (also called x64 or AMD64) is the 64-bit extension of the x86 architecture -- supporting 64-bit registers, 64-bit addressing, and backward compatibility with 32-bit and 16-bit code through multiple operation modes.
CPU Modes
| Mode | Bits | Addressing | OS |
|--------------|-------|-------------|--------------|
| Real Mode | 16 | 1 MB | DOS, BIOS |
| Protected | 32 | 4 GB | Linux, Win |
| Long Mode | 64 | Huge | 64-bit OS |
| Compatibility| 64 | 4 GB | 64-bit OS |
General Purpose Registers
64-bit 32-bit 16-bit 8-bit Purpose
─────────────────────────────────────────────
RAX EAX AX AL Accumulator
RBX EBX BX BL Base
RCX ECX CX CL Counter
RDX EDX DX DL Data
RSI ESI SI SIL Source Index
RDI EDI DI DIL Destination
RBP EBP BP BPL Base Pointer
RSP ESP SP SPL Stack Pointer
R8-R15 R8d-R15d R8w-R15w R8b-R15b Extended
Special Registers
RIP - Instruction Pointer (points to next instruction)
RFLAGS - Status flags (carry, zero, sign, overflow)
Instruction Set Highlights
; Data movement
mov rax, rbx ; copy register
mov rax, [mem] ; load from memory
mov [mem], rax ; store to memory
; Arithmetic
add rax, rbx ; rax = rax + rbx
sub rax, rbx ; rax = rax - rbx
imul rax, rbx ; signed multiply
idiv rbx ; signed divide
; Stack
push rax ; push onto stack
pop rax ; pop from stack
; Control flow
jmp label ; unconditional jump
je label ; jump if equal
call label ; call function
ret ; return from call
Common Mistakes
1. Using 32-bit registers for addresses
mov eax, [address] zero-extends to 64 bits. Use mov rax, [address] for full 64-bit addresses.
2. Forgetting REX prefixes
Instructions like mov r8, rax need a REX prefix. Most assemblers handle this automatically.
3. Calling conventions
Arguments go in RDI, RSI, RDX, RCX, R8, R9 on Linux (System V). On Windows, it's RCX, RDX, R8, R9.
FAQ
{{< faq question="Why is x86 so complex?" >}} x86 evolved over 40+ years while maintaining backward compatibility. Each generation added features (MMX, SSE, AVX) and widened registers (16->32->64 bit). {{< /faq >}}
{{< faq question="What is long mode?" >}} 64-bit mode where the CPU uses 64-bit registers and addressing. Only available on 64-bit operating systems with x86-64 processors. {{< /faq >}}
{{< faq question="What is the difference between RSP and RBP?" >}} RSP is the stack pointer (top of stack). RBP is the base pointer (frame reference). RBP helps debuggers generate stack traces. {{< /faq >}}
What's Next
Now learn about CPU registers in detail.
| Topic | Description | Link |
|---|---|---|
| Registers | GP and special registers | {{< ref "03-registers" >}} |
| Addressing | Memory addressing modes | {{< ref "04-addressing" >}} |
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro