Skip to content
Tutorials Center
My learning

Topics

Lesson 40 of 40 ยท Practice and Review

Assembly Cheat Sheet

One-page x86-64 and ARM64 reference: registers, instructions side by side, condition codes, calling conventions, Linux syscall numbers and gdb commands.

This page is the reference you keep open in a second window while reading disassembly or writing a small routine. It puts x86-64 (Intel syntax, destination first) and ARM64 (AArch64) next to each other, so you can translate in either direction. Everything here is explained properly elsewhere in the tutorial; follow the links when a row is not enough. The tables are read-only, and two small tools at the end let you check condition codes and register names interactively.

Real syntax, numbers and conventions below are for Linux unless a column says otherwise. When you work on another operating system, check the platform's own ABI document for anything marked as a convention (argument registers, system call numbers, reserved registers).

x86-64 registers

64-bit 32-bit 16-bit 8-bit Usual role
rax eax ax al (ah) return value, mul/div operand, syscall number
rbx ebx bx bl (bh) general; callee-saved
rcx ecx cx cl (ch) 4th argument (System V), shift count, loop counter
rdx edx dx dl (dh) 3rd argument, high half in mul/div
rsi esi si sil 2nd argument, string source
rdi edi di dil 1st argument, string destination
rbp ebp bp bpl frame pointer (or general); callee-saved
rsp esp sp spl stack pointer
r8 to r15 r8d to r15d r8w to r15w r8b to r15b general; r8, r9 are arguments 5 and 6; r12 to r15 are callee-saved

Also: rip (instruction pointer, usable in addressing as [rip+label]), rflags, and the vector registers xmm0 to xmm15 (ymm for AVX). Rule to remember: writing a 32-bit register zeroes the upper 32 bits; writing a 16- or 8-bit register keeps them. See The x86-64 Register Set.

ARM64 registers

Register Meaning
x0 to x30 64-bit general registers; w0 to w30 are their low 32 bits (writing a w register zeroes the upper half)
x0 to x7 arguments and results
x8 indirect result address; system call number on Linux
x9 to x15 temporaries (caller-saved)
x16, x17 intra-procedure-call scratch (used by linker veneers)
x18 platform register: reserved on Apple and Windows, do not use
x19 to x28 callee-saved
x29 frame pointer (fp)
x30 link register (lr): return address written by bl
sp stack pointer, 16-byte aligned for memory accesses
xzr / wzr zero register: reads as 0, ignores writes (the same encoding as sp in some instructions)
pc program counter, not a normal operand: use branches
v0 to v31 SIMD and floating-point registers (d0, s0 are the scalar views)

See ARM64 (AArch64) Basics.

Instructions side by side

Task x86-64 (Intel) ARM64
copy register mov rax, rbx mov x0, x1
load constant mov eax, 5 mov x0, #5
load from memory mov rax, [rbx] ldr x0, [x1]
store to memory mov [rbx], rax str x0, [x1]
indexed load mov rax, [rbx+rcx*8] ldr x0, [x1, x2, lsl #3]
address arithmetic lea rax, [rbx+rcx*4] add x0, x1, x2, lsl #2
add add rax, rbx add x0, x1, x2
subtract sub rax, rbx sub x0, x1, x2
multiply imul rax, rbx mul x0, x1, x2
signed divide cqo then idiv rbx (quotient rax, remainder rdx) sdiv x0, x1, x2 (remainder: msub)
unsigned divide xor edx, edx then div rbx udiv x0, x1, x2
and, or, xor and, or, xor and, orr, eor
bitwise not, negate not rax, neg rax mvn x0, x1, neg x0, x1
shift left, right shl, shr (logical), sar (arithmetic) lsl, lsr, asr
zero a register xor eax, eax mov x0, #0
sign-extend 32 to 64 movsxd rax, ebx sxtw x0, w1
zero-extend byte movzx eax, bl uxtb w0, w1
compare cmp rax, rbx cmp x0, x1
test bits test rax, rbx tst x0, x1
jump jmp label b label
conditional jump je label (after cmp) b.eq label (after cmp)
branch if zero test rax, rax / jz label cbz x0, label
conditional select cmovl rax, rbx csel x0, x1, x2, lt
call call func bl func
return ret ret (jumps to x30)
push push rax str x0, [sp, #-16]!
pop pop rax ldr x0, [sp], #16
enter the kernel syscall svc #0
do nothing nop nop

Two differences hide in this table. On x86-64 most arithmetic uses two operands (add rax, rbx means rax = rax + rbx) and may take a memory operand, while ARM64 uses three operands on registers only and reaches memory only through load and store instructions. The ARM64 stack pointer stays 16-byte aligned, so a "push" moves it by 16 even for one register (pairs use stp/ldp).

Addressing modes

Mode x86-64 ARM64
register [rbx] [x1]
register + constant [rbx+16] [x1, #16]
register + scaled index [rbx+rcx*4+8] [x1, x2, lsl #2] (no extra constant)
pre-index (update, then use) not available [x1, #16]!
post-index (use, then update) not available [x1], #16
relative to the instruction pointer [rip+label] adr/adrp + add, or ldr x0, label

See Arrays and Addressing Modes and ARM Load/Store, Conditions and Branches.

Condition codes

x86 suffix ARM64 Meaning after cmp a, b x86 flags
e / z eq a == b ZF = 1
ne / nz ne a != b ZF = 0
b / c lo / cc unsigned a < b CF = 1
ae / nc hs / cs unsigned a >= b CF = 0
be ls unsigned a <= b CF = 1 or ZF = 1
a hi unsigned a > b CF = 0 and ZF = 0
l lt signed a < b SF != OF
ge ge signed a >= b SF = OF
le le signed a <= b ZF = 1 or SF != OF
g gt signed a > b ZF = 0 and SF = OF
s mi negative result SF = 1
ns pl non-negative result SF = 0
o vs signed overflow OF = 1
no vc no signed overflow OF = 0

ARM's flags are called N, Z, C and V. They are only changed by flag-setting instructions (cmp, tst, adds, subs, ands). After a subtraction, ARM's C means "no borrow", the opposite of x86's CF, which is why the unsigned names map to lo/hs rather than to a flag name. Signed conditions use less/greater, unsigned ones use below/above (x86) or lower/higher (ARM).

Calling conventions

System V AMD64 Windows x64 AAPCS64 (ARM64)
Integer arguments rdi, rsi, rdx, rcx, r8, r9 rcx, rdx, r8, r9 x0 to x7
Float arguments xmm0 to xmm7 xmm0 to xmm3 v0 to v7
Extra arguments on the stack on the stack, after 32 bytes of shadow space on the stack
Return value rax (rdx for the second half), xmm0 rax, xmm0 x0 (x1), v0
Caller-saved rax, rcx, rdx, rsi, rdi, r8 to r11, all xmm rax, rcx, rdx, r8 to r11, xmm0 to xmm5 x0 to x15, x16, x17
Callee-saved rbx, rbp, r12 to r15 rbx, rbp, rdi, rsi, r12 to r15, xmm6 to xmm15 x19 to x28, x29, low half of v8 to v15
Stack alignment 16 bytes at the call 16 bytes at the call 16 bytes whenever sp is used
Special red zone of 128 bytes; al = number of vector registers for variadic calls shadow space; no red zone return address in x30; x18 reserved on some platforms

See Calling Conventions and Stack Frames, Prologues and Epilogues.

Linux system calls

x86-64 ARM64
Instruction syscall svc #0
Call number in rax x8
Arguments in rdi, rsi, rdx, r10, r8, r9 x0 to x5
Result in rax (small negative values are -errno) x0 (the same convention)
Clobbered by the instruction rcx, r11 none besides x0
Call x86-64 number ARM64 number
read(fd, buf, count) 0 63
write(fd, buf, count) 1 64
openat(dirfd, path, flags, mode) 257 56
close(fd) 3 57
mmap(...) 9 222
munmap(addr, length) 11 215
brk(addr) 12 214
getpid() 39 172
execve(path, argv, envp) 59 221
exit(status) 60 93
exit_group(status) 231 94

The numbers differ because each architecture's Linux port has its own table; never reuse one architecture's numbers on the other. A complete program is in Project: Hello World the Real Way, and the background in System Calls and Talking to the OS.

gdb commands

Goal Command
start and stop at the first instruction starti
breakpoint at a symbol or address break main, break *0x401000
run, continue run, continue
step one instruction, step over calls stepi (si), nexti (ni)
Intel syntax set disassembly-flavor intel
disassemble disassemble, x/10i $pc
show the next instruction at every stop display/i $pc
registers info registers, info registers rax rsp, p/x $rax
memory x/8xb $rsp (bytes), x/4xg $rsp (8-byte words), x/s $rsi (string)
call stack bt
split screen with registers and code layout regs, layout asm

On ARM64 the registers are $x0 to $x30, $sp and $pc. For lldb, use register read, memory read, disassemble and thread step-inst. The walkthrough is in Debugging at the Instruction Level.

The toy CPU in one glance

The runnable examples throughout this tutorial use a small interpreter with the registers rax, rbx, rcx, rdx, rsi, rdi and rsp (some lessons add r8), the flags ZF, SF, CF and OF, 32-bit values and one value per memory cell. Its instructions are mov add sub cmp test and or xor not shl shr sar imul div neg inc dec push pop jmp call ret loop out halt, the whole jcc family and cmovcc; syscall appears in the hello-world and practice lessons. It follows x86 flag rules, so everything in the condition-code table above works in it.

Two tools to try

The first prints which condition codes are true after a cmp for several pairs of values, using the exact flag formulas from the tables. Read each column as one cmp a, b.

JS Which conditions hold after cmp a, b?

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Compare the columns -1,1 and 1,-1: signed (l, g) and unsigned (b, a) conditions point in opposite directions, because -1 is the largest unsigned number. The last column, 2147483647,-1, is the one where subtracting overflows, so l and g need OF as well as SF.

The second tool resolves a register name to the full register it belongs to and says what a write to it does.

JS Register alias lookup

Press Run (or Ctrl + Enter) to see the console output here.

No output.

x31 is not a name you can write: encoding 31 means sp or xzr depending on the instruction, and the assembler makes you choose which you mean.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which pair of names refers to the same condition (unsigned a < b after cmp)?

    jb tests CF = 1, the unsigned below condition. ARM64 calls it lo (also cc). jl and b.lt are the signed pair; ja and b.hi mean unsigned above.
  2. 2. Which registers carry the first two integer arguments on Linux x86-64 and on ARM64?

    System V AMD64 passes arguments in rdi, rsi, rdx, rcx, r8, r9. AAPCS64 starts at x0. rcx and rdx are the first two on Windows x64.
  3. 3. What is the Linux system call number for write on x86-64 and on ARM64?

    write is 1 on x86-64 and 64 on ARM64. The pair 60 and 93 is exit. Each architecture has its own syscall table.
  4. 4. Which statement about ARM64 flags is correct?

    Ordinary add and sub leave the flags alone; adds and subs (and the aliases cmp and tst) set them. After a subtraction, ARM sets C when there was no borrow, the opposite of x86's CF.

Summary

  • x86-64 has 16 general registers with 64/32/16/8-bit names; ARM64 has x0 to x30 (and w views) plus sp and xzr. 32-bit writes zero-extend on both.
  • x86-64 arithmetic is two-operand and can use memory; ARM64 is three-operand and load/store.
  • Signed conditions (l, g; lt, gt) and unsigned conditions (b, a; lo, hi) read different flags; ARM sets flags only on request.
  • Argument registers: System V rdi, rsi, rdx, rcx, r8, r9; Windows rcx, rdx, r8, r9; ARM64 x0 to x7.
  • Linux system calls: number in rax/x8; write is 1/64 and exit is 60/93.
  • gdb's stepi, info registers, x/ and disassemble are the core of instruction-level debugging.

That is the end of the tutorial's reference material. Go back to Practice Exercises with Solutions whenever you want more practice, or revisit What Is Assembly Language? to see the whole picture again.