Home/Instructions/Load Word
LW

RISC-V LW Instruction Details

Instruction ManualI-type

Load a 32-bit word from memory into rd

Instruction Syntax

lw rd, offset(rs1)
Operand Breakdown
Destination rd: general-purpose register receiving the result.
Source rs1: register holding the first operand.
Immediate imm: 12-bit signed value, sign-extended before operation with rs1.
RV32IMemory Load

Instruction Behavior

LW (I-type, opcode=0000011, funct3=010) loads a 32-bit word from memory at the effective address (rs1 + sign-extended 12-bit offset), sign-extends it to XLEN, and writes it to rd. Naturally aligned word addresses are multiples of 4. When rd=x0, exceptions and side effects still occur even though value is discarded. This is the primary load instruction in RV32I.

LW Decode And Execute Animation

Starts with machine-code field decoding, then shows operand reads, instruction-specific execution, and ISA-visible state update.

rd
imm
rs1
lw
,
(
)
Execution Context
a0(x10)
0x00001000
mem[0x00001000]
0x80000002

This EEI branch applies only when the effective address is not divisible by 4; a naturally aligned access must not raise an address-misaligned exception.

31..20
19..15
14..12
11..7
6..0
000000000000
imm[11:0]
01010
rs1
010
funct3
00101
rd
0000011
opcode
Execution Data Path
instruction
0x00052283
opcode
0000011 -> LOAD
funct3
010 -> LW
rd / base
t0(x5) / a0(x10)=0x00001000
offset
000000000000 -> 0; ea=0x00001000 (naturally aligned (4-byte))
load
32-bit 0x80000002 -> sign extend
x5
t0(x5) = 0x80000002
Current Step

Concept Step: receive the 32-bit instruction encoding

The machine code is split by the current instruction format; the animation starts from encoding/decode.

encoding: 0x00052283
syntax : lw t0(x5), 0(a0(x10))
result : t0(x5) = 0x80000002
Architectural Result
t0(x5) = 0x80000002

This animation shows ISA-visible decode and state changes, not any specific CPU pipeline, cache, prediction, or timing implementation.

Quick Understanding & Search Notes

LW reads a 32-bit word from the effective address formed by rs1 plus a signed 12-bit offset, then sign-extends the value to XLEN and writes rd.

All base loads form an effective byte address as rs1 plus a sign-extended 12-bit offset.
Naturally aligned accesses should not raise address-misaligned exceptions; misaligned behavior depends on the execution environment interface.

Official Spec Notes

These notes are checked against the RISC-V Unprivileged ISA manual and summarize operation semantics, immediate ranges, and edge behavior.

Common Usage Scenarios

Data Loading

Understand this scenario with real code like «lw x5, 0(x10) # x5 = mem[x10+0][31:0]».

Register Operations

Understand this scenario with real code like «lw x5, 0(x10) # x5 = mem[x10+0][31:0]».

Pre-Use Checklist

Syntax Check
  • Verify the immediate field is within the valid range.
  • Confirm source register rs1 points to the correct operand.
Semantic Check
  • Check if the immediate sign-extension matches expectations.
  • Ensure the result register rd has a clear purpose.

Pitfalls / Common Confusions

A word address divisible by 4 is naturally aligned and must not raise an address-misaligned exception; the EEI defines the behavior of misaligned accesses
rd=x0 discards load value but still causes memory side effects

FAQ

What offset range does LW use?

Base load instructions use a sign-extended 12-bit byte offset, typically -2048 through 2047.

What is the difference between signed and unsigned loads?

LB/LH/LW sign-extend the loaded value to XLEN; LBU/LHU zero-extend. On RV64, use LWU when a 32-bit word should be zero-extended.