mfctr
Move from Count Register - 7C 09 02 A6
mfctr

Instruction Syntax

Mnemonic Format Description
mfctr rD Move from Count Register

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
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
Reserved 11-15 00000
Reserved 16-20 00000
Reserved 21-29 000000000
Reserved 30 0
SPR 31-31 Special Purpose Register (9 = CTR)

Operation

rD ← CTR

The contents of the Count Register (CTR) are copied into register rD.

Affected Registers

General Purpose Register (rD)

(always)

Examples

Basic Move from Count Register

mfctr r3     # Copy CTR value to r3

Save and Restore CTR

# Save CTR before using it
mfctr r10        # Save current CTR value
mtctr r3         # Set CTR for new purpose
# ... use CTR ...
mtctr r10        # Restore original CTR value

Loop Counter Check

# Check remaining loop iterations
li r3, 10        # Set initial count
mtctr r3         # Load into CTR
loop:
    # ... loop body ...
    mfctr r4     # Get current CTR value
    cmpwi r4, 0  # Check if zero
    bne loop     # Continue if not zero

Function Address Retrieval

# Get function address from CTR
mfctr r3         # Get address from CTR
# r3 now contains the function address
# Can be used for debugging or analysis

Dynamic Code Analysis

# Analyze code execution flow
mfctr r3         # Get current execution address
# r3 contains the address where execution will continue
# Useful for debugging or profiling

Related Instructions

mtctr, bctr, bcctr, bdnz, bdnzt, bdnzf

Back to Index