Site Tools

Sidebar

Smart Card Solution

User Manual

JavaCard API Samples

Java Card Specification

Knowledge Sharing

javacard:jcvm:7.5_the_java_card_virtual_machine_instruction_set

7.5 The Java Card Virtual Machine Instruction Set

Java virtual machine instructions are represented in this chapter by entries of the form shown in TABLE 7-1, an example instruction page, in alphabetical order.

mnemonic

Short description of the instruction.

Format

mnemonic

operand1

operand2

Forms

mnemonic = opcode

Stack

…, value1, value2 →

…/ value3

Description

A longer description detailing constraints on operand stack contents or constant pool entries, the operation performed, the type of the results, and so on.

Runtime Exception

If any runtime exceptions can be thrown by the execution of an instruction, that instruction must not throw any runtime exceptions except for instances of System Exception.

Notes

Commands not strictly part of the specification of an instruction are set aside as notes at the end of the description.

Each cell in the instruction format diagram represents a single 8-bit byte. The instruction's mnemonic is its name. Its opcode is its numeric representation and is given in both decimal and hexadecimal forms. Only the numeric representation is actually present in the Java Card virtual machine code in a CAP file.

Keep in mind that there are “operands” generated at compile time and embedded within Java Card virtual machine instructions, as well as “operands” calculated at run time and supplied on the operand stack. Although they are supplied from several different areas, all these operands represent the same thing: values to be operated upon by the Java Card virtual machine instruction being executed. By implicitly taking many of its operands from its operand stack, rather than representing them explicitly in its compiled code as additional operand bytes, register numbers, etc., the Java Card virtual machine's code stays compact.

Some instructions are presented as members of a family of related instructions sharing a single description, format, and operand stack diagram. As such, a family of instructions includes several opcodes and opcode mnemonics; only the family mnemonic appears in the instruction format diagram, and a separate forms line lists all member mnemonics and opcodes. For example, the forms line for the sconst_ family of instructions, giving mnemonic and opcode information for the two instructions in that family (sconst_0 and sconst_1), is

Forms sconst_0 = 3 (0x3), sconst_1 = 4 (0x4)

In the description of the Java Card virtual machine instructions, the effect of an instruction's execution on the operand stack ( Section 3.5, Frames) of the current frame ( Section 3.5, Frames) is represented textually, with the stack growing from left to right and each word represented separately. Thus,

Stack…, value1, value2 → …, result

shows an operation that begins by having a one-word value2 on top of the operand stack with a one-word value1 just beneath it. As a result of the execution of the instruction, value1 and value2 are popped from the operand stack and replaced by a one-word result, which has been calculated by the instruction. The remainder of the operand stack, represented by an ellipsis (…), is unaffected by the instruction's execution.

The type int takes two words on the operand stack. In the operand stack representation, each word is represented separately using a dot notation:

Stack…, value1.word1, value1.word2, value2.word1, value2.word2 → …, result.word1, result.word2

The Virtual Machine Specification for the Java Card Platform, v2.2.2 does not mandate how the two words are used to represent the 32-bit int value; it only requires that a particular implementation be internally consistent.

javacard/jcvm/7.5_the_java_card_virtual_machine_instruction_set.txt · Last modified: 2017/05/13 04:11 (external edit)