Assembly Cheat Sheet
Last updated
Program structure
A program without the C library starts at the label the linker is told about, usually _start.
| Element | Code |
|---|---|
| Section for fixed data | section .data |
| Section for zeroed buffers | section .bss |
| Section for instructions | section .text |
| Make the entry point visible to the linker | global _start |
| A label (a named address) | _start: |
| Comment | ; everything after a semicolon |
| End the program with exit code 0 | mov rax, 60 → mov rdi, 0 → syscall |
Registers
Sixteen 64-bit general-purpose registers. Each has smaller names for its lower 32, 16 and 8 bits.
| Register and common use | 64 / 32 / 16 / 8-bit names |
|---|---|
| Accumulator, system call number, return value | rax eax ax al |
| Base, kept across function calls | rbx ebx bx bl |
| Counter, 4th function argument | rcx ecx cx cl |
Data, 3rd argument, upper half of mul and div | rdx edx dx dl |
| Source index, 2nd argument | rsi esi si sil |
| Destination index, 1st argument | rdi edi di dil |
| Stack pointer, top of the stack | rsp esp sp spl |
| Base pointer, stack frame | rbp ebp bp bpl |
Extra registers, shown for r8; r9 to r15 follow the same pattern | r8 r8d r8w r8b |
| Instruction pointer, address of the next instruction | rip |
Flags set by cmp, test and arithmetic | rflags |
Data directives
Directives are read by the assembler and reserve or name memory; they are not instructions.
| Meaning | Code |
|---|---|
| Define bytes: a string and a newline | msg db "Hello", 10 |
| Define a 16-bit word | year dw 2026 |
| Define a 32-bit doubleword | count dd 1000 |
| Define a 64-bit quadword | big dq 123456789 |
Reserve 64 zeroed bytes (in .bss) | buffer resb 64 |
| Reserve 10 quadwords | table resq 10 |
| Name a constant | max equ 100 |
| Length of the data just above | len equ $ - msg |
| Repeat a definition | zeros times 8 db 0 |
Moving data
The destination comes first. Square brackets mean the memory at that address.
| Operation | Code |
|---|---|
| Number into a register | mov rax, 42 |
| Register into a register | mov rbx, rax |
| Address of a label into a register | mov rsi, msg |
| Read 8 bytes from memory | mov rax, [big] |
| Write a register to memory | mov [big], rax |
| Write one byte, with the size spelled out | mov byte [buffer], 10 |
| Read memory at register plus offset | mov al, [rsi + 1] |
| Indexed: base + index * scale + offset | mov rax, [table + rcx * 8] |
| Compute an address without reading memory | lea rax, [rsi + rcx * 2] |
| Load a byte and zero the rest of the register | movzx eax, byte [rsi] |
| Swap two registers | xchg rax, rbx |
Arithmetic and logic
Two-operand instructions write their result to the first operand. mul, div and idiv also use rax and rdx on their own. Flag effects vary: not leaves the flags unchanged, and div and idiv leave them undefined.
| Operation | Code |
|---|---|
| Add | add rax, rbx |
| Subtract | sub rax, 5 |
| Add 1 / subtract 1 | inc rcx / dec rcx |
| Signed multiply into a register | imul rax, rbx |
Unsigned multiply: rdx:rax = rax * rbx | mul rbx |
Divide the unsigned value in rax by rbx: clear rdx first; quotient in rax, remainder in rdx | xor rdx, rdx → div rbx |
Signed divide: sign-extend rax into rdx first | cqo → idiv rbx |
| Negate | neg rax |
| Bitwise and, or, xor, not | and rax, 0xff / or rax, rbx / xor rax, rbx / not rax |
| Set a register to zero (short and fast) | xor eax, eax |
| Shift left (multiply by 2 per bit) | shl rax, 3 |
| Shift right: unsigned / signed | shr rax, 1 / sar rax, 1 |
Compare and jump
cmp subtracts without storing the result and sets the flags; a conditional jump then reads them.
| Operation | Code |
|---|---|
| Compare two values | cmp rax, rbx |
| Check bits (and without storing), often to test for zero | test rax, rax |
| Jump always | jmp done |
| Jump if equal / zero | je done / jz done |
| Jump if not equal / not zero | jne loop_start / jnz loop_start |
| Signed: greater, greater or equal, less, less or equal | jg / jge / jl / jle |
| Unsigned: above, above or equal, below, below or equal | ja / jae / jb / jbe |
| Loop 10 times with a counter | mov rcx, 10 → again: → dec rcx → jnz again |
| Copy only if the condition holds (no jump) | cmovg rax, rbx |
Stack and functions
The stack grows down: push lowers rsp by 8, pop raises it.
| Operation | Code |
|---|---|
| Push a register / pop it back | push rbx / pop rbx |
| Call a function (pushes the return address) | call print_line |
| Return to the caller | ret |
| Reserve 32 bytes of local space | sub rsp, 32 |
| Release it | add rsp, 32 |
| Set up a stack frame | push rbp → mov rbp, rsp |
| Tear it down | mov rsp, rbp → pop rbp |
| Arguments, in order (System V, Linux and macOS) | rdi rsi rdx rcx r8 r9 |
Registers a function must restore before ret | rbx rbp r12 r13 r14 r15 |
Linux system calls
Put the number in rax and the arguments in rdi, rsi, rdx, r10, r8, r9, then run syscall. The result comes back in rax; a negative value is an error code.
| Call | Registers |
|---|---|
read(fd, buffer, count) | rax = 0 rdi = fd rsi = buffer rdx = count |
write(fd, buffer, count) | rax = 1 rdi = fd rsi = buffer rdx = count |
open(path, flags, mode) | rax = 2 rdi = path rsi = flags rdx = mode |
close(fd) | rax = 3 rdi = fd |
exit(code) | rax = 60 rdi = code |
| Standard input, output, error | fd 0 fd 1 fd 2 |
| Registers the kernel overwrites | rcx r11 |
Assemble, run and inspect
On a Linux machine with NASM and the GNU tools installed.
| Task | Command |
|---|---|
| Assemble to an object file | nasm -f elf64 main.asm -o main.o |
| Link into a program | ld main.o -o main |
| Run it and show its exit code | ./main; echo $? |
| Disassemble, Intel syntax | objdump -d -M intel main |
| Step through it in a debugger | gdb ./main |
| See the assembly a C compiler writes | gcc -S -O2 -masm=intel file.c |
The registers, instructions and system calls you reach for most when writing x86-64 assembly, on one page. Every row is NASM syntax (Intel operand order, destination first) for 64-bit Linux, the same toolchain as Coddy's Assembly playground and course. New to assembly? What is assembly language walks through a complete program line by line, and what is machine code shows the bytes it becomes.
Every instruction here assembles with nasm -f elf64. Try any of them in the Assembly playground, which assembles, links and runs your program in the browser with nothing to install, or learn them step by step in the free Assembly course.
Assembly cheat sheet FAQ
Is this assembly cheat sheet free?
Yes. The whole cheat sheet is free to read, with no sign-up. Bookmark it and come back when you need a register name, an instruction or a system call number.
Which assembly does this cheat sheet cover?
mov rax, rbx copies rbx into rax. The GNU assembler's default AT&T syntax reverses the order and adds prefixes, writing movq %rbx, %rax. ARM64 and RISC-V have different instructions and registers.What is the difference between mov and lea?
mov rax, [rsi + 8] reads the 8 bytes stored at the address rsi + 8. lea rax, [rsi + 8] only computes the address and puts the number in rax, without touching memory. Because it can add and scale registers in one step, lea is also used as a quick calculator, for example lea rax, [rbx + rbx * 4] to multiply rbx by 5.Why is xor eax, eax used to zero a register?
xor eax, eax is 2 bytes long, while mov rax, 0 takes 5 or more. Writing a 32-bit register such as eax also clears the upper half of rax, so the whole 64-bit register becomes 0. Processors recognize this instruction and handle it without waiting on the old value.What are the 64, 32, 16 and 8-bit register names for?
rax is all 64 bits, eax the lower 32, ax the lower 16 and al the lowest 8. They let you work with bytes and smaller numbers, for example mov al, [rsi] reads one character of a string. Writing eax clears the upper 32 bits; writing ax or al leaves the rest unchanged.Can I run these instructions online?
Yes. The Assembly playground on Coddy assembles x86-64 NASM, links it and runs it on Linux, then shows the output and any errors. You can paste rows from this cheat sheet into a program and run it in the browser.