tw
Trap Word - 7C 00 00 08
tw
Instruction Syntax
Mnemonic | Format | Flags |
tw | TO,rA,rB | None |
Instruction Encoding
0
1
1
1
1
1
T
T
T
T
T
A
A
A
A
A
B
B
B
B
B
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) |
TO | 6-10 | Trap condition |
rA | 11-15 | Source register A |
rB | 16-20 | Source register B |
Reserved | 21-29 | 000000000 |
Reserved | 30-31 | 00 |
Operation
If condition specified by TO is met, then trap
The tw instruction compares the values in registers rA and rB according to the condition specified by TO. If the condition is met, a program interrupt is generated.
Note: The tw instruction is used for conditional trapping based on register comparisons. Common trap conditions include equal, less than, greater than, etc.
Affected Registers
Program Counter (PC)
- May be redirected to trap handler if condition is met
Examples
Basic Trap
tw 4, r3, r4 # Trap if r3 == r4 (TO = 4 for equal)
Conditional Trapping
# Trap if value exceeds limit lwz r3, value # Load value lwz r4, limit # Load limit tw 12, r3, r4 # Trap if r3 > r4 (TO = 12 for greater than)
Debugging
# Trap for debugging purposes tw 31, r0, r0 # Always trap (TO = 31)