Site Tools


Sidebar

Smart Card Solution

User Manual

JavaCard API Samples

Java Card Specification

Knowledge Sharing

javacard:jcvm:7.5.94_slookupswitch

7.5.94 slookupswitch

Access jump table by key match and jump

Format

slookupswitch

defaultbyte1

defaultbyte2

npairs1

npairs2

match-offset pairs…

Pair Format

matchbyte1

matchbyte2

offsetbyte1

offsetbyte2

Forms

slookupswitch = 117 (0x75)

Stack

…, key → …

Description

A slookupswitch instruction is a variable-length instruction. Immediately after the slookupswitch opcode follow a signed 16-bit value default, an unsigned 16-bit value npairs, and then npairs pairs. Each pair consists of a short match and a signed 16-bit offset. Each of the signed 16-bit values is constructed from two unsigned bytes as (byte1 « 8) | byte2.

The table match-offset pairs of the slookupswitch instruction must be sorted in increasing numerical order by match.

The key must be of type short and is popped from the operand stack and compared against the match values. If it is equal to one of them, then a target address is calculated by adding the corresponding offset to the address of the opcode of this slookupswitch instruction. If the key does not match any of the match values, the target address is calculated by adding default to the address of the opcode of this slookupswitch instruction. Execution then continues at the target address.

The target address that can be calculated from the offset of each match-offset pair, as well as the one calculated from default, must be the address of an opcode of an instruction within the method that contains this slookupswitch instruction.

Notes

The match-offset pairs are sorted to support lookup routines that are quicker than linear search.

javacard/jcvm/7.5.94_slookupswitch.txt · Last modified: 2017/05/13 04:10 (external edit)