typestar

Language basics

31 steps in 9 sets of Assembly.

Assembly is the floor every other language stands on: instructions the processor executes directly, registers instead of variables, flags instead of booleans, and syscalls where a runtime would be. This tour speaks NASM for x86-64 Linux — the dialect of most tutorials and of osdev culture — and every seed is a complete program that assembles, links, and runs, most of them handing their computed answer out as the exit code: the machine's own way of returning a value.

The route runs from a five-line exit through the whole working vocabulary: mov and the register views, add through div with rdx's double duty, data sections with db/dw/dq and equ, the cmp-and-jump loop shape, scaled addressing over arrays, push/pop and the call/ret pair, lea's free arithmetic, byte-at-a-time string work, cmov and setcc for branch-free logic, two's complement, jump tables, and the rbp stack frame every compiler emits. The Encore is three honest programs: a decimal printer built on div, FizzBuzz spoken in remainders, and a nested-loop triangle.

Start this tour

First programs

Arithmetic

  • add and subIn-place arithmetic: the first operand is the destination.
  • mul and divMultiplication and division live in rax; rdx catches the rest.
  • Two's complementneg flips sign; signed jumps read it correctly.

Data

Control flow

  • cmp and jumpscmp sets the flags; the j-family branches on them.
  • The loop shapeA label, a compare, a conditional jump back: every loop ever.
  • dec and jnzThe tightest countdown: decrement until the zero flag.
  • Jump tablesIndex into addresses instead of chaining compares.

Bits & flags

  • Bitwiseand, or, xor, shl: arithmetic below arithmetic.
  • Shift and maskPull packed fields out of a value.
  • test and setccFlag questions become byte answers.
  • cmovPick a value from flags without branching.

The stack

  • push and popThe stack grows down; last in, first out swaps for free.
  • call and retcall pushes the return address; ret pops and jumps back.
  • Stack framesrbp anchors locals at fixed offsets: the classic prologue.

Memory & strings

Talking to Linux

Encore

The other Assembly tours