Site Tools


Sidebar

Smart Card Solution

User Manual

JavaCard API Samples

Java Card Specification

Knowledge Sharing

javacard:jcvm:7.5.50_ilookupswitch

7.5.50 ilookupswitch

Access jump table by key match and jump

Format

ilookupswitch

defaultbyte1

defaultbyte2

npairs1

npairs2

match-offset pairs…

Pair Format

matchbyte1

matchbyte2

matchbyte3

matchbyte4

offsetbyte1

offsetbyte2

Forms

ilookupswitch = 118 (0x76)

Stack

…, key.word1, key.word2 → …

Description

An ilookupswitch instruction is a variable-length instruction. Immediately after the ilookupswitch opcode follow a signed 16-bit value default, an unsigned 16-bit value npairs, and then npairs pairs. Each pair consists of an int match and a signed 16-bit offset. Each match is constructed from four unsigned bytes as (matchbyte1 « 24) | (matchbyte2 « 16) | (matchbyte3 « 8) | matchbyte4. Each offset is constructed from two unsigned bytes as (offsetbyte1 « 8) | offsetbyte2.

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

The key must be of type int 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 ilookupswitch 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 ilookupswitch 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 ilookupswitch instruction.

Notes

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

If a virtual machine does not support the int data type, the ilookupswitch instruction will not be available.

javacard/jcvm/7.5.50_ilookupswitch.txt · Last modified: 2017/05/13 04:09 (external edit)