Lesson 2.1: x86-64 Architecture Overview
Learning Objectives
- Explain the design principles behind x86-64 (register extensions, backwards compatibility).
- Identify key hardware features relevant to assembly (e.g., expanded register set).
Prerequisites
- Basic knowledge of x86 registers (from Section 1).
- Familiarity with 32-bit vs. 64-bit architectures.
Key Concepts
- Extended Registers:
rax,rbx,rcx,rdx,r8–r15 - RIP-relative addressing: A new feature in x86-64
- Compatibility: 64-bit mode vs. legacy mode
Detailed Explanation
x86-64 Evolution
x86-64 (also known as AMD64 or Intel 64) extends the x86 architecture to 64 bits while maintaining backward compatibility:
- Extended Address Space: Can address up to 16 EB (exabytes) theoretically
- More Registers: 16 general-purpose registers instead of 8
- Wider Registers: All registers extended to 64 bits
- Improved Calling Conventions: More efficient parameter passing
Register Extensions
In 64-bit mode, additional registers r8 through r15 are available, each 64 bits wide:
| Register | 64-bit | 32-bit | 16-bit | 8-bit |
|---|---|---|---|---|
| Extended #8 | R8 | R8D | R8W | R8B |
| Extended #9 | R9 | R9D | R9W | R9B |
| ... | ... | ... | ... | ... |
| Extended #15 | R15 | R15D | R15W | R15B |
RIP-Relative Addressing
RIP-relative addressing allows referencing memory relative to the instruction pointer, useful for position-independent code:
; Example of RIP-relative addressing
mov rax, [rip + some_label] ; Load from address relative to current instruction
lea rbx, [rip + data_table] ; Get address of data_table
...
some_label:
dq 0x11223344
data_table:
dq 0x1000, 0x2000, 0x3000
Operating Modes
- Long Mode (64-bit): Native x86-64 mode with full 64-bit capabilities
- Compatibility Mode: Runs 32-bit and 16-bit code within 64-bit OS
- Legacy Mode: Traditional 32-bit x86 mode
Memory Model
x86-64 uses a flat memory model with virtual addressing:
- Virtual Address Space: Each process has its own 64-bit address space
- Canonical Addresses: Only lower 48 bits typically used
- Segmentation: Largely obsolete in 64-bit mode
Exercises & Practice Problems
Question: Which registers are new in x86-64 as opposed to x86?
Answer: r8, r9, r10, r11, r12, r13, r14, r15. These provide 8 additional general-purpose registers beyond the original 8.
Exercise: Inspect code compiled as position-independent (-fPIC) and observe RIP-relative addressing in the disassembly.
Solution: Compile with gcc -fPIC -c file.c then objdump -d file.o. Look for instructions like mov rax, [rip+0x...] or lea rdi, [rip+0x...].
Recommended Resources
- Intel® 64 and IA-32 Architectures Software Developer's Manual, Vol. 1 (Architecture)
- Position-Independent Code (GCC)