lw
Load word
Loads the 32-bit word at the address in the second register plus an offset into the first, sign-extended on RV64.
Used in
- Loads, stores and immediatesRISC-V assembly
- .data, .text and directivesRISC-V assembly
- Going 64-bitRISC-V assembly
- Memory regions and executable filesRISC-V assembly
- if, else and jump tablesRISC-V assembly
- LoopsRISC-V assembly
- Arrays and stringsRISC-V assembly
- The stack and spRISC-V assembly
- jal, ret and the calling conventionRISC-V assembly
- Floating point and the F and D extensionsRISC-V assembly
Forms
lw , ()
Pseudo-instructions
The processor does not have these forms. The assembler replaces each of them with one or more real instructions. Open a row to see them.
-
Set t1 to contents of memory word at label's address
-
Load from Address
Operands
t1- Any integer register,
x0tox31, or its named alias, such aszero,t0ort6. imm12- A signed 12-bit immediate,
-2048to2047. t2- An integer register. It may be the same register as
t1. imm- An immediate value: a signed 12-bit value (
-2048to2047) or a 32-bit value (-2147483648to4294967295). The size your value needs decides which real instructions the assembler uses. Open the row to see them for each size. label- A named address in the program, such as the start of a loop or a variable in
.data.
This example runs on RV64.
# value is initialized and naturally aligned for this operation.
.data
value: .word 0x817fff80
.text
la t0, value
# The word 0x817FFF80 sign-extends in RV64; lw writes −2122317952 (0xFFFFFFFF817FFF80) to t2.
lw t2, 0(t0)