mfsprg
Move from SPRG - 7C 00 02 A6
mfsprg
Instruction Syntax
Mnemonic | Format | Flags |
mfsprg | rD,SPRGn | None |
Instruction Encoding
0
1
1
1
1
1
D
D
D
D
D
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
Field | Bits | Description |
Primary Opcode | 0-5 | 011111 (0x1F) |
rD | 6-10 | Destination register |
rA | 11-15 | 00000 (unused) |
rB | 16-20 | 00000 (unused) |
XO | 22-29 | 01010110 (0x56) |
Operation
rD ← SPRGn
MFSPRG copies the contents of the specified Special Purpose Register General (SPRGn) into the destination register rD.
- Reads the value from the specified SPRG register
- Copies it to the destination register rD
Note: SPRG registers are used for temporary storage during exception handling.
Affected Registers
General Purpose Registers (GPRs)
- rD (Destination register) - Loaded with SPRG value
Examples
Basic SPRG Read
# Read SPRG0 mfsprg r3, 0 # r3 = SPRG0 # Read SPRG1 mfsprg r4, 1 # r4 = SPRG1
Exception Handler
# In an exception handler exception_handler: mfsprg r3, 0 # Get saved register value # Process the exception using the saved value
Context Switch
# Save context in SPRG registers mtsprg 0, r3 # Save r3 in SPRG0 mtsprg 1, r4 # Save r4 in SPRG1 # ... context switch ... mfsprg r3, 0 # Restore r3 from SPRG0 mfsprg r4, 1 # Restore r4 from SPRG1
Related Instructions
mtsprg (Move to SPRG), mfsrr0 (Move from SRR0), mfsrr1 (Move from SRR1), mfdar (Move from DAR)