cmpwi
Compare Word Immediate - 2C 00 00 00
cmpwi
Instruction Syntax
Mnemonic | Format | Flags |
cmpwi | crfD, rA, SIMM | None |
Instruction Encoding
0
0
1
0
1
1
D
D
D
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 | 011100 (0x1C) |
crfD | 6-8 | Condition Register Field |
rA | 11-15 | Source register |
SIMM | 16-31 | Signed immediate value (16-bit) |
Operation
CR[crfD] ← (rA) - EXTS(SIMM)
CMPWI compares the value in register rA with a 16-bit signed immediate value and sets the specified Condition Register field based on the result.
- Subtracts the immediate value from the register
- Sets the CR field: LT, GT, EQ, SO
Note: Used for signed comparisons. For unsigned, use cmplwi.
Affected Registers
- Condition Register (CR field specified by crfD)
Examples
# Compare r3 with 0 cmpwi r3, 0 beq is_zero bne not_zero # Compare r4 with -1 cmpwi r4, -1 blt less_than_minus_one # Compare for threshold cmpwi r5, 100 bge above_threshold