Effective Address
Store instructions form the effective byte address by adding rs1 to a sign-extended 12-bit offset. SW uses the same -2048 to 2047 offset range.
RISC-V Unprivileged ISA, RV32I load and store instructionsStore the full 32-bit value of rs2 to memory
SW uses opcode 0100011 (0x23), funct3 010. The rs1 field holds the base address, rs2 holds the store data, and the 12-bit immediate split across imm[11:5] and imm[4:0] provides the offset.
SW (S-type, opcode=0100011, funct3=010) stores the low 32 bits of rs2 to the effective address (rs1 + sign-extended 12-bit offset). Naturally aligned word addresses are multiples of 4. This is the primary store instruction in RV32I, used to save register values to memory.
SW forms the effective address as rs1 plus a signed 12-bit offset and stores the low 32 bits of rs2 to memory.
These notes are checked against the RISC-V Unprivileged ISA manual and summarize operation semantics, immediate ranges, and edge behavior.
Store instructions form the effective byte address by adding rs1 to a sign-extended 12-bit offset. SW uses the same -2048 to 2047 offset range.
RISC-V Unprivileged ISA, RV32I load and store instructionsSW stores the low 32 bits of rs2 to memory; it does not store the full XLEN-wide register value.
RISC-V Unprivileged ISA, RV32I load and store instructionsUnderstand this scenario with real code like «sw x5, 0(x10) # mem[x10+0][31:0] = x5[31:0]».
Understand this scenario with real code like «sw x5, 0(x10) # mem[x10+0][31:0] = x5[31:0]».
Understand this scenario with real code like «sw x5, 0(x10) # mem[x10+0][31:0] = x5[31:0]».
SW stores only the low 32 bits of rs2, not necessarily the full XLEN-wide register.
The effective address is the base register rs1 plus a sign-extended 12-bit byte offset.