Logo
Articles Compilers Libraries Books MiniBooklets Assembly C++ Rust Go Linux CPU Others Videos
Advertisement

Article by Ayman Alheraki on May 12 2026 12:58 PM

x86-64 Registers — Complete Technical Guide with REX Extension

x86-64 Registers — Complete Technical Guide with REX Extension

x86-64 architecture extends the original x86 CPU register set from 8 to 16 general-purpose registers while maintaining full backward compatibility. This is achieved using a mechanism called the REX prefix, which adds one additional bit to existing 3-bit register fields.


1. CPU Registers Overview

Registers are the fastest storage units inside the CPU. They are used for:

  • Arithmetic and logical operations

  • Function calls and return values

  • Memory addressing

  • Loop control

  • System-level execution

In x86-64, registers are 64-bit wide, but can also be accessed in smaller forms:

SizeExample
64-bitRAX
32-bitEAX
16-bitAX
8-bitAL / AH

2. Original x86 Register Limitation

In the original x86 architecture:

  • Registers were encoded using 3 bits

  • This allowed only 8 registers

Mathematical limit:

$2^3 = 8$


Legacy x86 Registers (8 registers)

BinaryDecimalRegisterRole
0000RAXArithmetic, return value
0011RCXLoop counter
0102RDXMultiplication/division helper
0113RBXGeneral purpose
1004RSPStack pointer
1015RBPFrame pointer
1106RSISource index
1117RDIDestination index

3. Why x86-64 Needed Expansion

Modern software requires:

  • More function arguments

  • More temporary registers for optimization

  • Reduced memory access overhead

Thus, AMD introduced 8 additional registers:

  • R8 to R15

However, the instruction encoding format could not be changed for backward compatibility.


4. REX Prefix Solution

The REX prefix is a single byte added before the opcode:

It is always in the range:


REX Bit Meaning

BitFunction
W64-bit operand size
RExtends REG field
XExtends SIB index field
BExtends R/M or base field

5. Core Mechanism of Extension

x86 uses a 3-bit register field. REX adds one additional bit.

Thus, registers become 4-bit values:

$\text{Register ID} = (\text{REX bit} \ll 3) + \text{3-bit field}$


6. Full x86-64 Register Table

Complete Mapping of 16 Registers

REX3-bit4-bitDecimalRegisterDescription
000000000RAXArithmetic / return value
000100011RCXLoop counter
001000102RDXMultiply/divide
001100113RBXGeneral purpose
010001004RSPStack pointer
010101015RBPFrame pointer
011001106RSISource index
011101117RDIDestination index
100010008R8Function arguments / temporary
100110019R9Function arguments / temporary
1010101010R10Temporary register
1011101111R11Scratch register
1100110012R12Callee-saved register
1101110113R13Base/index register
1110111014R14Callee-saved register
1111111115R15Callee-saved register

7. How REX Computes Registers

Example: R10

  • REX = 1

  • 3-bit = 010

$(1 \ll 3) + 2 = 10$

Result: R10


Example: R13

  • REX = 1

  • 3-bit = 101

$(1 \ll 3) + 5 = 13$

Result: R13


8. Where REX Applies

REX extends multiple instruction fields:

FieldExtended by
REG fieldREX.R
R/M fieldREX.B
SIB indexREX.X
Operand sizeREX.W

9. Real Machine Code Example

Instruction:

Machine code:


Step 1: Decode REX (4C)

Binary:

Breakdown:

  • W = 1 → 64-bit operation

  • R = 1 → REG extended

  • X = 0

  • B = 0


Step 2: Decode ModR/M (D0)

Binary:

Split:

  • REG = 010

  • R/M = 000


Step 3: Apply REX Extension

  • REG becomes R10

  • R/M remains RAX


Final Instruction:


10. Functional Role of Registers

RAX

  • Arithmetic operations

  • Function return values

RCX

  • Loop counter

  • Shift operations

RDX

  • Multiplication/division support

RBX

  • General-purpose storage

RSP

  • Stack pointer (critical system register)

RBP

  • Stack frame base pointer

RSI / RDI

  • String and memory operations

R8–R15

  • Function arguments and compiler temporary registers


11. Calling Convention (System V ABI)

ArgumentRegister
1stRDI
2ndRSI
3rdRDX
4thRCX
5thR8
6thR9

12. Key Insight

The REX system does not change the original x86 encoding. It only adds one extra bit:

  • Old registers: 000–111 (RAX–RDI)

  • Extended registers: 1000–1111 (R8–R15)


13. Final Mental Model

x86-64 register encoding can be understood as:

  • Original 3-bit field defines base register

  • REX adds the missing most significant bit

So:

  • 0xxx = legacy registers

  • 1xxx = extended registers


Conclusion

x86-64 achieves register expansion without breaking compatibility by using a simple but powerful idea: a single prefix byte (REX) that extends existing 3-bit register fields into 4-bit addressing space, enabling 16 general-purpose registers while preserving the entire legacy x86 ecosystem.

Advertisements

Responsive Counter
General Counter
1311525
Daily Counter
1956