Getting everything ready for you…

Loading courses, problems and your progress. This takes just a moment.

0s

Assembly (x86-64) Cheat Sheet

Build and debug

// assemble, link, run, debug
nasm -f elf64 prog.asm -o prog.o
ld prog.o -o prog
./prog; echo $?
gdb ./prog
objdump -d -M intel prog

Data and sections

// data definitions
section .data
msg db "Hi", 10, 0
n dq 42
arr dd 1, 2, 3
len equ $ - msg
section .bss
buf resb 128

Core instructions

mov rax, rbx
mov rax, [rbx + 8]
lea rax, [rbx + rcx*4]
add rax, 5
sub rax, rbx
imul rax, rbx
cqo
idiv rbx
and rax, 0xFF
xor rax, rax
shl rax, 2

Control flow

cmp rax, rbx
je equal
jne different
jg bigger
jl smaller
ja above
jb below
jmp somewhere
cmovl rax, rbx

Stack and functions

push rbx
pop rbx
call func
ret
push rbp
mov rbp, rsp
sub rsp, 16
leave

Linux system calls

// write(1, msg, len)
mov rax, 1
mov rdi, 1
mov rsi, msg
mov rdx, len
syscall
// exit(0)
mov rax, 60
xor rdi, rdi
syscall

Full Assembly (x86-64) documentation