Menu
CoddyTech

Assembly Cheat Sheet

Last updated

Program structure

A program without the C library starts at the label the linker is told about, usually _start.

ElementCode
Section for fixed datasection .data
Section for zeroed bufferssection .bss
Section for instructionssection .text
Make the entry point visible to the linkerglobal _start
A label (a named address)_start:
Comment; everything after a semicolon
End the program with exit code 0mov 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 use64 / 32 / 16 / 8-bit names
Accumulator, system call number, return valuerax eax ax al
Base, kept across function callsrbx ebx bx bl
Counter, 4th function argumentrcx ecx cx cl
Data, 3rd argument, upper half of mul and divrdx edx dx dl
Source index, 2nd argumentrsi esi si sil
Destination index, 1st argumentrdi edi di dil
Stack pointer, top of the stackrsp esp sp spl
Base pointer, stack framerbp ebp bp bpl
Extra registers, shown for r8; r9 to r15 follow the same patternr8 r8d r8w r8b
Instruction pointer, address of the next instructionrip
Flags set by cmp, test and arithmeticrflags

Data directives

Directives are read by the assembler and reserve or name memory; they are not instructions.

MeaningCode
Define bytes: a string and a newlinemsg db "Hello", 10
Define a 16-bit wordyear dw 2026
Define a 32-bit doublewordcount dd 1000
Define a 64-bit quadwordbig dq 123456789
Reserve 64 zeroed bytes (in .bss)buffer resb 64
Reserve 10 quadwordstable resq 10
Name a constantmax equ 100
Length of the data just abovelen equ $ - msg
Repeat a definitionzeros times 8 db 0

Moving data

The destination comes first. Square brackets mean the memory at that address.

OperationCode
Number into a registermov rax, 42
Register into a registermov rbx, rax
Address of a label into a registermov rsi, msg
Read 8 bytes from memorymov rax, [big]
Write a register to memorymov [big], rax
Write one byte, with the size spelled outmov byte [buffer], 10
Read memory at register plus offsetmov al, [rsi + 1]
Indexed: base + index * scale + offsetmov rax, [table + rcx * 8]
Compute an address without reading memorylea rax, [rsi + rcx * 2]
Load a byte and zero the rest of the registermovzx eax, byte [rsi]
Swap two registersxchg 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.

OperationCode
Addadd rax, rbx
Subtractsub rax, 5
Add 1 / subtract 1inc rcx / dec rcx
Signed multiply into a registerimul rax, rbx
Unsigned multiply: rdx:rax = rax * rbxmul rbx
Divide the unsigned value in rax by rbx: clear rdx first; quotient in rax, remainder in rdxxor rdx, rdx → div rbx
Signed divide: sign-extend rax into rdx firstcqo → idiv rbx
Negateneg rax
Bitwise and, or, xor, notand 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 / signedshr rax, 1 / sar rax, 1

Compare and jump

cmp subtracts without storing the result and sets the flags; a conditional jump then reads them.

OperationCode
Compare two valuescmp rax, rbx
Check bits (and without storing), often to test for zerotest rax, rax
Jump alwaysjmp done
Jump if equal / zeroje done / jz done
Jump if not equal / not zerojne loop_start / jnz loop_start
Signed: greater, greater or equal, less, less or equaljg / jge / jl / jle
Unsigned: above, above or equal, below, below or equalja / jae / jb / jbe
Loop 10 times with a countermov 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.

OperationCode
Push a register / pop it backpush rbx / pop rbx
Call a function (pushes the return address)call print_line
Return to the callerret
Reserve 32 bytes of local spacesub rsp, 32
Release itadd rsp, 32
Set up a stack framepush rbp → mov rbp, rsp
Tear it downmov rsp, rbp → pop rbp
Arguments, in order (System V, Linux and macOS)rdi rsi rdx rcx r8 r9
Registers a function must restore before retrbx 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.

CallRegisters
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, errorfd 0 fd 1 fd 2
Registers the kernel overwritesrcx r11

Assemble, run and inspect

On a Linux machine with NASM and the GNU tools installed.

TaskCommand
Assemble to an object filenasm -f elf64 main.asm -o main.o
Link into a programld main.o -o main
Run it and show its exit code./main; echo $?
Disassemble, Intel syntaxobjdump -d -M intel main
Step through it in a debuggergdb ./main
See the assembly a C compiler writesgcc -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?
x86-64, the 64-bit instruction set of Intel and AMD processors, in NASM syntax on Linux. NASM uses Intel operand order, so 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?
Any value xor itself is 0, and 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?
They name smaller parts of the same register. 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.

Coddy programming languages illustration

Learn Assembly with Coddy

Get started