Site Tools


Sidebar

Smart Card Solution

User Manual

JavaCard API Samples

Java Card Specification

Knowledge Sharing

javacard:jcvm:7.5.106_stableswitch

7.5.106 stableswitch

Access jump table by short index and jump

Format

stableswitch

defaultbyte1

defaultbyte2

lowbyte1

lowbyte2

highbyte1

highbyte2

jump offsets…

Offset Format

offsetbyte1

offsetbyte2

Forms

stableswitch = 115 (0x73)

Stack

…, index → …

Description

A stableswitch instruction is a variable-length instruction. Immediately after the stableswitch opcode follow a signed 16-bit value default, a signed 16-bit value low, a signed 16-bit value high, and then high - low + 1 further signed 16-bit offsets. The value low must be less than or equal to high. The high - low + 1 signed 16-bit offsets are treated as a 0-based jump table. Each of the signed 16-bit values is constructed from two unsigned bytes as (byte1 « 8) | byte2.

The index must be of type short and is popped from the stack. If index is less than low or index is greater than high, than a target address is calculated by adding default to the address of the opcode of this stableswitch instruction. Otherwise, the offset at position index - low of the jump table is extracted. The target address is calculated by adding that offset to the address of the opcode of this stableswitch instruction. Execution then continues at the target address.

The target addresses that can be calculated from each jump table offset, as well as the one calculated from default, must be the address of an opcode of an instruction within the method that contains this stableswitch instruction.

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