← Back to writing

NOTE / SYSTEMS

Reading x86-64 addressing modes

A working note on registers, memory operands, and the details that make assembly readable.

Start with the operand

An instruction becomes easier to parse when I first identify which operand is being read and which is being written. A register is immediate state; a memory operand adds an address calculation.

The useful pattern

The common base-plus-index-times-scale form expresses an address without hiding its parts. Naming those parts while reading code makes pointer arithmetic and array access much less mysterious.

For example, a base register can identify the beginning of an array while an index register selects an element. The scale is limited to values supported by the instruction encoding, so the addressing mode is compact but not a general arithmetic expression.

Why it matters

These details show up in bootloaders, kernels, compilers, and optimised programs. Reading the address calculation separately from the instruction's operation makes low-level code less magical and makes mistakes easier to localise.