stw
Store Word - 90 00 00 00
stw

Instruction Syntax

Mnemonic Format Flags
stw rS,d(rA) None

Instruction Encoding

1
0
0
1
0
0
S
S
S
S
S
A
A
A
A
A
I
I
I
I
I
I
I
I
I
I
I
I
I
I
I
I

Field Bits Description
Primary Opcode 0-5 100100 (0x24)
rS 6-10 Source register
rA 11-15 Base register
SIMM 16-31 Signed immediate offset

Operation

EA ← (rA) + SIMM
(EA) ← (rS)

The effective address is calculated by adding the signed immediate offset to the base register. The word (32-bit value) in the source register is stored at the effective address.

Note: The stw instruction stores a 32-bit word to memory. The address must be aligned to a 4-byte boundary.

Affected Registers

Memory

Examples

Basic Store Word

# Store word from r1 to memory
stw r1, 0(r3)     # Store at address in r3
stw r1, 4(r3)     # Store at address r3 + 4

Array of Words

# Store word in array
li r4, 0            # Array index
slwi r4, r4, 2      # Multiply by 4 (word size)
add r5, r3, r4      # Calculate address
stw r1, 0(r5)       # Store word

Data Structure Access

# Store word in data structure
li r3, struct_base  # Load structure base address
li r4, 8            # Offset to field
stw r1, 8(r3)       # Store word at struct.field

Related Instructions

stwu, stwux, stwx, lwz

Back to Index