# Linux Kernel Module Cheat

### 29.2. x86 addressing modes

Example: userland/arch/x86_64/address_modes.S

Several x86 instructions can calculate addresses of a complex form:

    s:a(b, c, d)

which expands to:

    a + b + c * d

Where the instruction encoding allows for:

- `a`: any 8 or 32-bit general purpose register

- `b`: any 32-bit general purpose register except ESP

- `c`: 1, 2, 4 or 8 (encoded in 2 SIB bits)

- `d`: immediate constant

- `s`: a segment register. Cannot be tested simply from userland, so we won’t talk about them here. See: https://github.com/cirosantilli/x86-bare-metal-examples/blob/6606a2647d44bc14e6fd695c0ea2b6b7a5f04ca3/segment_registers_real_mode.S

The common compiler usage is:

- `a`: base pointer

- `b`: array offset

- `c` and `d`: struct offset

Bibliography:

- Intel 64 and IA-32 Architectures Software Developer’s Manuals Volume 1 3.7.5 "Specifying an Offset"

- https://sourceware.org/binutils/docs-2.18/as/i386_002dMemory.html