Contents Prev Next Up


The Virtual Machine Instruction Set


Table Jumping

tableswitch
lookupswitch

tableswitch

Access jump table by index and jump

..., index => ...

tableswitch is a variable length instruction. Immediately after the tableswitch opcode, between zero and three 0's are inserted as padding so that the next byte begins at an address that is a multiple of four. After the padding follow a series of signed 4-byte quantities: default-offset, low, high, and then high-low+1 further signed 4-byte offsets. The high-low+1 signed 4-byte offsets are treated as a 0-based jump table.

The index should be an integer. If index is less than low or index is greater than high, then default-offset is added to the pc. Otherwise, low is subtracted from index, and the index-low'th element of the jump table is extracted, and added to the pc.

lookupswitch

Access jump table by key match and jump

..., key => ...

lookupswitch is a variable length instruction. Immediately after the lookupswitch opcode, between zero and three 0's are inserted as padding so that the next byte begins at an address that is a multiple of four.

Immediately after the padding are a series of pairs of signed 4-byte quantities. The first pair is special. The first item of that pair is the default offset, and the second item of that pair gives the number of pairs that follow. Each subsequent pair consists of a match and an offset.

The key should be an integer. The integer key on the stack is compared against each of the matches. If it is equal to one of them, the offset is added to the pc. If the key does not match any of the matches, the default offset is added to the pc.


Contents Prev Next Up

Generated with CERN WebMaker