stwu
Store Word with Update - 94 00 00 00
stwu

Instruction Syntax

Mnemonic Format Flags
stwu rS,d(rA) None

Instruction Encoding

1
0
0
1
0
1
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 100101 (0x25)
rS 6-10 Source register
rA 11-15 Base register (updated)
SIMM 16-31 Signed immediate offset

Operation

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

STWU stores a word (32-bit value) to memory AND automatically updates the base register to point to the next location.

  1. Calculates address = base register + offset
  2. Stores the word from source register to that address
  3. Updates the base register to point to the address where it just stored

Note: This is perfect for storing data in arrays or buffers because it automatically moves to the next location.

Affected Registers

General Purpose Registers (GPRs)

Memory

Examples

Basic Store Word with Update

# Store word and automatically move to next location
stwu r1, 4(r3)    # Store r1 at address r3+4, then r3 = r3+4

Fill an Array

# Fill array with values 1, 2, 3, 4, 5
li r3, array        # Point to start of array
li r1, 1            # First value to store
stwu r1, 4(r3)      # Store 1, r3 now points to next location
li r1, 2            # Second value
stwu r1, 4(r3)      # Store 2, r3 moves to next location
li r1, 3            # Third value  
stwu r1, 4(r3)      # Store 3, r3 moves to next location
# ... and so on

Store Multiple Values

# Store calculated values in a buffer
li r3, buffer       # Point to buffer
li r4, 10           # Number of values to store
loop:
add r5, r6, r7      # Calculate some value
stwu r5, 4(r3)      # Store it, automatically move to next spot
addi r4, r4, -1     # Decrement counter
cmpwi r4, 0         # Are we done?
bne loop            # If not, continue

Related Instructions

stw, stwux, stwx, lwu

Back to Index