if_icmp<eq,ne,lt,le,gt,ge>

Branch if int comparison succeeds

Bytecode

Type Description
u1 if_icmpeq opcode = 0x9F (159)
s2 branchoffset
Type Description
u1 if_icmpne opcode = 0xA0(160)
s2 branchoffset
Type Description
u1 if_icmplt opcode = 0xA1 (161)
s2 branchoffset
Type Description
u1 if_icmple opcode = 0xA2 (162)
s2 branchoffset
Type Description
u1 if_icmpgt opcode = 0xA3 (163)
s2 branchoffset
Type Description
u1 if_icmpge opcode = 0xA4 (164)
s2 branchoffset

Stack ..., value1, value2 => ...

Description Both value1 and value2 must be of type int. They are both popped from the operand stack and compared. All comparisons are signed. The results of the comparison are as follows:

If the comparison succeeds, the unsigned branchbyte1 and branchbyte2 are used to construct a signed 16-bit offset, where the offset is calculated to be (branchbyte1 << 8) | branchbyte2. Execution then proceeds at that offset from the address of the opcode of this if_icmp<cond> instruction. The target address must be that of an opcode of an instruction within the method that contains this if_icmp<cond> instruction.

Otherwise, execution proceeds at the address of the instruction following this if_icmp<cond> instruction.

Example

    bipush 2        ; push the int 2 onto the stack
    iload_1         ; push the int value in local variable 1 onto the stack
    if_icmpeq Label ; if the value of local variable 1 equals 2, jump to Label
    return          ; return if not equal
Label:
    ; execution continues here if local variable 1 equals 2...