x86-64 Registers and Assembly Explained: Cheat Sheet for Beginners [CPU Simulator]

INSIGHTS6 min read
x86-64 registers explained with CPU simulator

x86-64 registers are the small, very fast storage slots inside the CPU that every instruction works with. There are 16 general-purpose 64-bit registers (RAX, RBX, RCX, RDX, RSI, RDI, RBP, RSP and R8 to R15), plus the instruction pointer RIP and the flags register RFLAGS. Each 64-bit register can also be used through smaller names: EAX is the lower 32 bits of RAX, AX the lower 16, and AL the lowest 8.

This guide explains the registers, the stack, the instructions you will read first, calling conventions and how to step through code in a debugger. Start with the CPU simulator below: it makes the rules much easier to remember.

Interactive CPU simulator

In Lab 1, run instructions on RAX and see exactly which bytes change. In Lab 2, step through a short program with arithmetic, the stack and a loop.

Lab 1 ยท One register, four names
See RAX, EAX, AX, AH and AL change
RAX is a 64-bit register. EAX is its lower 32 bits, AX the lower 16, and AH and AL the two bytes of AX. Run an instruction and watch which bits change. One rule surprises everyone: writing EAX clears the upper 32 bits.
Lab 2 ยท CPU step simulator
Step through a program, one instruction at a time
A tiny x86-64 program in Intel syntax: arithmetic, the stack and a loop. Press Step to execute the highlighted line and watch the registers, the zero flag and the stack.

x86-64 general-purpose registers

64-bit32-bit16-bit8-bit lowCommon use
raxeaxaxalReturn value, arithmetic
rbxebxbxblGeneral use, preserved across calls
rcxecxcxclCounter, 4th argument (System V)
rdxedxdxdl3rd argument, high half of multiply and divide
rsiesisisil2nd argument, source for string operations
rdiedididil1st argument, destination for string operations
rbpebpbpbplFrame pointer (base of the current stack frame)
rspespspsplStack pointer (top of the stack)
r8 to r15r8dr8wr8bExtra registers, 5th and 6th arguments in r8 and r9

Two more registers matter constantly: RIP holds the address of the next instruction, and RFLAGS holds status flags such as ZF (zero), SF (sign), CF (carry, unsigned overflow) and OF (signed overflow). Comparisons set the flags, and conditional jumps read them.

The partial register rule

Writing a 32-bit register such as mov eax, 1 clears the upper 32 bits of RAX. Writing a 16-bit or 8-bit register such as mov ax, 1 or mov al, 1 leaves the other bits untouched. That is why xor eax, eax is the usual way to set all of RAX to zero.

The instructions you will read first

InstructionWhat it does
mov rax, rbxCopy RBX into RAX
mov rax, [rbx]Load 8 bytes from the address in RBX
lea rax, [rbx+rcx*4+8]Calculate an address (or any sum) without reading memory
add rax, 5 / sub rax, 5Add or subtract, updating the flags
inc rcx / dec rcxAdd or subtract 1
imul rax, rbxSigned multiply
and, or, xor, notBitwise operations
shl rax, 2 / shr rax, 2Shift left or right (multiply or divide by powers of 2)
cmp rax, rbxCompare: subtract without storing, only set the flags
test rax, raxBitwise AND without storing. Sets ZF if RAX is zero
jmp labelJump always
push rax / pop raxPut a value on the stack or take it off
call func / retCall a function (pushes the return address) and return
syscallAsk the Linux kernel to do something

Conditional jumps

JumpAfter cmp a, b jumps ifSigned or unsigned
je / jza == b (ZF = 1)Both
jne / jnza != b (ZF = 0)Both
jg / jla > b / a < bSigned
jge / jlea >= b / a <= bSigned
ja / jba > b / a < bUnsigned
jae / jbea >= b / a <= bUnsigned

Seeing ja or jb in disassembly tells you the compiler treated the values as unsigned. jg and jl mean signed. Mixing them up is a classic source of bugs and vulnerabilities.

How the stack works

The stack is a region of memory that grows towards lower addresses. RSP always points to the top item. push rax subtracts 8 from RSP and stores RAX there. pop rax loads the top item into RAX and adds 8 to RSP. A call pushes the return address, and ret pops it back into RIP. A typical function starts and ends like this:

my_func:
    push rbp            ; save the caller's frame pointer
    mov  rbp, rsp       ; start a new frame
    sub  rsp, 32        ; room for local variables
    ; ... function body ...
    mov  rsp, rbp       ; free the locals
    pop  rbp            ; restore the caller's frame pointer
    ret                 ; jump back to the return address

If a function writes past the end of a local buffer, it can overwrite the saved RBP and the return address above it. That is the core idea behind a stack buffer overflow, and why reverse engineers watch the stack so closely.

Calling conventions

System V (Linux, macOS)Windows x64
Integer argumentsrdi, rsi, rdx, rcx, r8, r9rcx, rdx, r8, r9
Return valueraxrax
Preserved by the calleerbx, rbp, r12 to r15rbx, rbp, rdi, rsi, r12 to r15
Stack16-byte aligned at each call16-byte aligned, plus 32 bytes of shadow space

Hello world in x86-64 assembly (Linux)

; hello.asm  (NASM, Intel syntax)
section .data
    msg db "Hello, world", 10
    len equ $ - msg

section .text
    global _start
_start:
    mov rax, 1      ; syscall number 1 = write
    mov rdi, 1      ; file descriptor 1 = stdout
    mov rsi, msg    ; address of the text
    mov rdx, len    ; number of bytes
    syscall
    mov rax, 60     ; syscall number 60 = exit
    xor edi, edi    ; exit code 0
    syscall
nasm -f elf64 hello.asm -o hello.o
ld hello.o -o hello
./hello

Intel vs AT&T syntax

Intel (NASM, IDA, Ghidra, x64dbg)AT&T (GNU as, objdump default)
Operand ordermov rax, 5 (destination first)movq $5, %rax (source first)
Registersrax%rax
Memory[rbp-8]-8(%rbp)

Make tools show Intel syntax with objdump -d -M intel ./prog, or set disassembly-flavor intel in GDB.

Step through real code with GDB

gdb ./hello
(gdb) set disassembly-flavor intel
(gdb) break _start
(gdb) run
(gdb) stepi              # execute one instruction
(gdb) info registers     # show all registers
(gdb) x/4gx $rsp         # show 4 values from the top of the stack
(gdb) disassemble

Frequently asked questions

What are the registers in x86-64?

x86-64 has 16 general-purpose 64-bit registers: RAX, RBX, RCX, RDX, RSI, RDI, RBP, RSP and R8 to R15. It also has the instruction pointer RIP, the RFLAGS register, and vector registers such as XMM0 to XMM15 for floating point and SIMD.

What is the difference between RAX and EAX?

RAX is the full 64-bit register and EAX is its lower 32 bits. Writing to EAX also clears the upper 32 bits of RAX, while writing to the 16-bit AX or 8-bit AL only changes those bits.

What does the RSP register do?

RSP is the stack pointer. It always holds the address of the top of the stack. push decreases RSP by 8 and stores a value, pop loads a value and increases RSP by 8, and call and ret use the stack to store and restore the return address.

Which registers hold function arguments in x86-64?

On Linux and macOS (System V), the first six integer arguments go in RDI, RSI, RDX, RCX, R8 and R9. On Windows x64, the first four go in RCX, RDX, R8 and R9. In both, the return value is in RAX.

Is x86-64 assembly hard to learn?

Reading assembly is easier than most people expect: a few dozen instructions cover most real code. Start with registers, mov, add, cmp, jumps and the stack, step through small programs in a debugger, and compare simple C code with its disassembly.

Where to go next

Registers and the stack are the foundation of reverse engineering and exploit development. Assembly through stack techniques, writing, compiling and testing shellcode, and the Linux internals underneath are covered lesson by lesson in Assembly and Shellcode Development.