sw
lyszt.net covers sw and other RISC-V instructions in more detail.
Encoding format
Description
Stores a register value to memory. In sw rs2, offset(rs1), the address is the value in rs1 plus offset, and the low 32 bits of rs2 are written there. The first operand names the source and the second the address, the reverse of the order in lw.
Official definition
RV32I is a load-store architecture, where only load and store instructions access memory and arithmetic instructions only operate on CPU registers. RV32I provides a 32-bit address space that is byte-addressed. The EEI will define what portions of the address space are legal to access with which instructions (e.g., some addresses might be read only, or support word access only). Loads with a destination of x0 must still raise any exceptions and cause any other side effects even though the load value is discarded.
The LW instruction loads a 32-bit value from memory into rd. LH loads a 16-bit value from memory, then sign-extends to 32-bits before storing in rd. LHU loads a 16-bit value from memory but then zero extends to 32-bits before storing in rd. LB and LBU are defined analogously for 8-bit values. The SW, SH, and SB instructions store 32-bit, 16-bit, and 8-bit values from the low bits of register rs2 to memory.
Example
la t0, slot li t1, 99 sw t1, 0(t0) # memory at slot now holds 99