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.
First programs
- The smallest programLoad the exit syscall's number and make the call: five lines.
- sys_writefd, buffer, length in rdi, rsi, rdx — then syscall.
- Registers and movCopy between registers; 32-bit writes zero the top half.
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
- Data sizesdb, dw, dq: bytes, words, quadwords, declared and measured.
- Loads and storesbyte, word, qword at memory — and movzx to widen cleanly.
- equ and timesAssemble-time constants and repetition.
- memcpy by handLoad a byte, store a byte, walk both pointers.
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
- Scaled addressingbase + index * size reaches array slots in one operand.
- leaCompute an address without loading it: free arithmetic.
- strlen by handWalk bytes until the zero terminator.
- The register shuffleFibonacci in three registers, no memory at all.
Talking to Linux
- Digits to textA number becomes printable by adding '0'.
- stdout and stderrFile descriptors are numbers: 1 and 2 are two streams.
- argc and argvAt _start the stack holds argc, then the argv pointers.
Encore
- print_decimal.asmUnsigned to decimal: divide by ten, build the digits backward.
- fizzbuzz.asmThe classic, spoken in remainders and sys_write.
- triangle.asmNested loops draw a hash triangle one row at a time.