What is Addressing mode?
The way an instruction specifies the address of data or a jump target. Examples include immediate, register, base register plus offset and PC-relative.
Japanese name: アドレッシングモード
The way an instruction specifies the address of data or a jump target. Examples include immediate, register, base register plus offset and PC-relative.
Japanese name: アドレッシングモード
Immediate uses a constant written in the instruction itself. Register uses the value of a register. Base register plus offset reads or writes the memory at the address obtained by adding a constant to a register value. Writing “lw a0, 8(sp)” in RISC-V reads from the address 8 above the value of sp. PC-relative specifies a location by its distance from the address of the instruction being executed. It is used for branch targets and for code that works wherever it is placed. x86 also offers a form that adds, to a base register, another register multiplied by 2, 4 or 8 plus a constant, so that an array element can be read with one instruction.
In RISC-V, the only way to specify an address when reading or writing memory is base register plus offset. The address calculation is a single addition, which keeps instruction decoding and the pipeline simple. In exchange, reading an array element first requires instructions that shift and add the index. x86 has many forms and does the same job in fewer instructions, but decoding is more complex. It is a choice between the number of instructions and the complexity of each one.
A variable on the stack is specified by an offset from the stack pointer. A field in a structure is an offset from a pointer to the structure. An array element is at the base address plus the index multiplied by the element size. A branch target is specified PC-relative. The number of bits available for an offset is limited, so the reach is fixed. A RISC-V conditional branch reaches about 4 KiB either way, and an unconditional jump about 1 MiB either way. For farther targets, the upper bits of the address are first built in a register with another instruction.
Yes. The x86 instruction LEA only calculates an address and does not access memory. It is also used to perform an addition and a multiplication by a small number together.
The upper bits of the address are placed in a register with another instruction, and the remainder is added as an offset. Assemblers and compilers generate this combination automatically.
As an Amazon Associate I earn from qualifying purchases.
This page was drafted with AI and fact-checked by a separate AI review before publication. Our Editorial policy explains how we write and check content. If you spot an error, please tell us on our Contact page.