risc-v

Definition

lw (RISC-V)

Loads a value from memory into a register. The memory address is computed by adding a sign-extended 12-bit immediate offset to the base register.

lw a, offset(b)

Equivalent C code:

a = *(int*)((char*)b + offset)

Example

If register x10 contains the base address 0x1000:

lw x12, 8(x10)

This loads the 32-bit word at memory address 0x1000 + 8 = 0x1008 into register x12.

The following diagram shows the same idea from the perspective of byte-addressable memory: each row is a 32-bit word, but each word still occupies four consecutive byte addresses.