sw
Store word
Stores the low 32 bits of t1 at the address in t2 plus an offset.
Used in
- Loads, stores and immediatesRISC-V assembly
- .data, .text and directivesRISC-V assembly
- The stack and spRISC-V assembly
- jal, ret and the calling conventionRISC-V assembly
- The bitmap display and the keyboard registersRISC-V assembly
- When an instruction cannot be carried outRISC-V assembly
- Variables in memory and constantsRISC-V assembly
- Fill an array with the numbers from 1 to 10RISC-V assembly
- Stack arguments and a stack frameRISC-V assembly
- Recursion: factorial and FibonacciRISC-V assembly
Forms
sw , ()
Pseudo-instructions
The assembler turns these into one or more real instructions.
-
Store t1 contents into effective memory word address
-
Store $t1 contents into effective memory word address
-
Store $t1 contents into effective memory word address using t2 as a temporary
-
Store $t1 contents into memory word at label's address using t2 as a temporary
-
Store to 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. imm32- A 32-bit immediate,
-2147483648to4294967295. label- A named address in the program, such as the start of a loop or a variable in
.data.
# value is initialized and naturally aligned for this operation.
.data
value: .word 0
.text
la t0, value
li t1, 42
# Store 42 (bytes 2A 00 00 00) at value; inspect Memory.
sw t1, 0(t0)