mcrxr
Move to Condition Register from XER - 4C 00 00 08
mcrxr
Instruction Syntax
Mnemonic | Format | Flags |
mcrxr | crfD | None |
Instruction Encoding
0
1
1
1
1
1
D
D
D
0
0
0
0
0
0
0
0
0
0
0
0
1
0
1
0
1
0
0
0
0
0
0
Field | Bits | Description |
Primary Opcode | 0-5 | 011111 (0x1F) |
crfD | 6-8 | Destination condition register field |
Reserved | 9-20 | Should be zero |
XO | 21-30 | 0x0A8 (168) - Extended opcode |
Reserved | 31 | Should be zero |
Operation
CR[4×crfD:4×crfD+3] ← XER[28:31]
The contents of the XER register bits 28-31 (CA, OV, SO) are copied to the destination condition register field (crfD). The XER bits correspond to carry, overflow, and summary overflow status.
Note: This instruction provides access to XER status bits for conditional branching. The XER bits copied are the carry bit (CA), overflow bit (OV), and summary overflow bit (SO), which are essential for testing arithmetic operation results.
Affected Registers
Condition Register (CR)
(always)
- CR[crfD] - Destination condition register field (LT, GT, EQ, SO bits)
XER (Exception Register)
(read only)
- XER - Source register (read only)
For more information on condition codes see Section 2.1.5, "XER Register," in the PowerPC Microprocessor Family: The Programming Environments manual.
Examples
Check Carry After Addition
# Check if addition produced carry addc r3, r1, r2 # Add with carry mcrxr cr1 # Copy XER to CR1 bt cr1, carry_occurred # Branch if carry occurred
Test Overflow Condition
# Check for arithmetic overflow addo r3, r1, r2 # Add with overflow detection mcrxr cr2 # Copy XER to CR2 bt cr2, overflow_detected # Branch if overflow occurred
Check Summary Overflow
# Check for summary overflow addo r3, r1, r2 # Add with overflow detection mcrxr cr3 # Copy XER to CR3 bt cr3, summary_overflow # Branch if summary overflow set
Multi-Precision Arithmetic
# Multi-precision addition with carry checking addc r3, r1, r2 # Add low-order words mcrxr cr1 # Save carry status adde r4, r5, r6 # Add high-order words with carry mcrxr cr2 # Save final carry status bt cr2, overflow_occurred # Check for final overflow
Overflow Detection in Loops
# Check for overflow in accumulation loop li r3, 0 # Initialize accumulator li r4, 100 # Loop counter loop: addo r3, r3, r5 # Add with overflow detection mcrxr cr1 # Copy XER to CR1 bt cr1, overflow_in_loop # Branch if overflow occurred addi r4, r4, -1 # Decrement counter cmpwi r4, 0 # Check if done bne loop # Continue if not done
Safe Arithmetic Operations
# Safe addition with overflow checking addo r3, r1, r2 # Add with overflow detection mcrxr cr1 # Copy XER to CR1 bt cr1, handle_overflow # Handle overflow condition # Continue with normal result if no overflow
Carry Chain Operations
# Chain carry operations addc r3, r1, r2 # First addition mcrxr cr1 # Save carry adde r4, r5, r6 # Second addition with carry mcrxr cr2 # Save second carry adde r7, r8, r9 # Third addition with carry mcrxr cr3 # Save final carry bt cr3, final_carry # Check final carry
Error Condition Testing
# Test for arithmetic error conditions addo r3, r1, r2 # Perform arithmetic operation mcrxr cr1 # Copy XER to CR1 # Test different error conditions bt cr1, carry_error # Branch if carry occurred bt cr1, overflow_error # Branch if overflow occurred bt cr1, summary_error # Branch if summary overflow
Status Preservation
# Preserve XER status across function calls addo r3, r1, r2 # Perform operation mcrxr cr7 # Save XER status in CR7 bl some_function # Function call (might modify XER) # Restore XER status for testing mcrxr cr0 # Get current XER status # Compare with saved status if needed
Complex Arithmetic Validation
# Validate complex arithmetic operation addo r3, r1, r2 # First operation mcrxr cr1 # Save status addo r4, r3, r5 # Second operation mcrxr cr2 # Save status addo r6, r4, r7 # Third operation mcrxr cr3 # Save final status # Check for any overflow in the chain bt cr1, first_overflow # Check first operation bt cr2, second_overflow # Check second operation bt cr3, third_overflow # Check third operation