twi
Trap Word Immediate - 0C 00 00 00
twi

Instruction Syntax

Mnemonic Format Flags
twi TO,rA,SIMM None

Instruction Encoding

0
0
1
1
0
0
T
T
T
T
T
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 001100 (0x0C)
TO 6-10 Trap condition
rA 11-15 Source register
SIMM 16-31 Signed immediate value

Operation

If condition specified by TO is met, then trap

The twi instruction compares the value in register rA with the signed immediate value according to the condition specified by TO. If the condition is met, a program interrupt is generated.

Note: The twi instruction is used for conditional trapping based on register-to-immediate comparisons. Common trap conditions include equal, less than, greater than, etc.

Affected Registers

Program Counter (PC)

Examples

Basic Trap

twi 4, r3, 0        # Trap if r3 == 0 (TO = 4 for equal)

Conditional Trapping

# Trap if value exceeds limit
lwz r3, value        # Load value
twi 12, r3, 100      # Trap if r3 > 100 (TO = 12 for greater than)

Debugging

# Trap for debugging purposes
twi 31, r0, 0        # Always trap (TO = 31)

Related Instructions

tw

Back to Index