Increment local variable by constant
Bytecode
For local variable numbers in the range 0-255, and values of <n> in the range -128 to 127, use:
Type | Description |
u1 | iinc opcode = 0x84 (132) |
u1 | <varnum> |
s1 | <n> |
There is also a wide format for this instruction, which supports access to all local variables from 0 to 65535, and values of <n> between -32768 and 32767:
Type | Description |
u1 | wide opcode = 0xC4 (196) |
u1 | iinc opcode = 0x84 (132) |
u2 | <varnum> |
s2 | <n> |
iinc increments the int held in the local variable <varnum> by <n>. The iinc instruction takes two parameters:
<varnum> is an unsigned integer which indicates which local variable should be used.
<n> is the integer amount to increment or decrement the variable by. <varnum> must be a valid local variable number in the current method's frame.
Example
iinc 1 10 ; increment local variable 1 by 10. iinc 1 -1 ; decrement local variable 1 by 1.
The iinc opcode can be used in conjunction with the wide instruction to access a local variable using a two-byte unsigned index and increment it by a two-byte immediate value.