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.
x86-64 general-purpose registers
| 64-bit | 32-bit | 16-bit | 8-bit low | Common use |
|---|---|---|---|---|
rax | eax | ax | al | Return value, arithmetic |
rbx | ebx | bx | bl | General use, preserved across calls |
rcx | ecx | cx | cl | Counter, 4th argument (System V) |
rdx | edx | dx | dl | 3rd argument, high half of multiply and divide |
rsi | esi | si | sil | 2nd argument, source for string operations |
rdi | edi | di | dil | 1st argument, destination for string operations |
rbp | ebp | bp | bpl | Frame pointer (base of the current stack frame) |
rsp | esp | sp | spl | Stack pointer (top of the stack) |
r8 to r15 | r8d | r8w | r8b | Extra 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
| Instruction | What it does |
|---|---|
mov rax, rbx | Copy 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, 5 | Add or subtract, updating the flags |
inc rcx / dec rcx | Add or subtract 1 |
imul rax, rbx | Signed multiply |
and, or, xor, not | Bitwise operations |
shl rax, 2 / shr rax, 2 | Shift left or right (multiply or divide by powers of 2) |
cmp rax, rbx | Compare: subtract without storing, only set the flags |
test rax, rax | Bitwise AND without storing. Sets ZF if RAX is zero |
jmp label | Jump always |
push rax / pop rax | Put a value on the stack or take it off |
call func / ret | Call a function (pushes the return address) and return |
syscall | Ask the Linux kernel to do something |
Conditional jumps
| Jump | After cmp a, b jumps if | Signed or unsigned |
|---|---|---|
je / jz | a == b (ZF = 1) | Both |
jne / jnz | a != b (ZF = 0) | Both |
jg / jl | a > b / a < b | Signed |
jge / jle | a >= b / a <= b | Signed |
ja / jb | a > b / a < b | Unsigned |
jae / jbe | a >= b / a <= b | Unsigned |
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 arguments | rdi, rsi, rdx, rcx, r8, r9 | rcx, rdx, r8, r9 |
| Return value | rax | rax |
| Preserved by the callee | rbx, rbp, r12 to r15 | rbx, rbp, rdi, rsi, r12 to r15 |
| Stack | 16-byte aligned at each call | 16-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 order | mov rax, 5 (destination first) | movq $5, %rax (source first) |
| Registers | rax | %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.


