mtspr
Move to Special Purpose Register - 7C 00 00 A6
mtspr

Instruction Syntax

Mnemonic Format Flags
mtspr SPR,rS None

Instruction Encoding

0
1
1
1
1
1
S
P
R
S
P
R
S
P
R
S
P
R
S
P
R
S
P
R
S
P
R
1
0
1
0
0
0
1
1
1
1
0

Field Bits Description
Primary Opcode 0-5 011111 (0x1F)
SPR 6-20 Special Purpose Register number
XO 21-30 0101000111 (0x287)
Reserved 31 Should be zero

Operation

SPR[SPR] ← rS

The contents of general-purpose register rS are copied to the specified Special Purpose Register (SPR).

Note: This instruction provides access to various system registers. Common SPR numbers include 8 (LR - Link Register), 9 (CTR - Count Register), and others for processor-specific functionality.

Affected Registers

Special Purpose Registers (SPRs)

(always)

General Purpose Registers (GPRs)

(read only)

Examples

Write Link Register

# Write to Link Register (SPR 8)
mtspr 8, r3            # Copy r3 to LR
# r3 now contains return address

Write Count Register

# Write to Count Register (SPR 9)
mtspr 9, r4            # Copy r4 to CTR
# r4 now contains loop counter value

Save Return Address

# Save return address before function call
mfspr r5, 8            # Save current LR
bl some_function       # Function call
mtspr 8, r5            # Restore original LR

Set Performance Counter

# Set performance monitoring counter
li r6, 1000            # Load counter value
mtspr 952, r6          # Set PMC1 (SPR 952)
# Performance counter now set to 1000

Related Instructions

mfspr, mtmsr, mfmsr

Back to Index