cmpwi
Compare Word Immediate - 2C 00 00 00
cmpwi

Instruction Syntax

MnemonicFormatFlags
cmpwicrfD, rA, SIMMNone

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
FieldBitsDescription
Primary Opcode0-5011100 (0x1C)
crfD6-8Condition Register Field
rA11-15Source register
SIMM16-31Signed 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.

  1. Subtracts the immediate value from the register
  2. Sets the CR field: LT, GT, EQ, SO

Note: Used for signed comparisons. For unsigned, use cmplwi.

Affected Registers

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

Related Instructions

cmplwi, cmpi, subf

Back to Index