Java Bytecode - Instructions

Instructions

See also: Java bytecode instruction listings

As each byte has 256 potential values, there are 256 possible opcodes. Of these, 0x00 through 0xca, 0xfe, and 0xff are assigned values. 0xca is reserved as a breakpoint instruction for debuggers and is not used by the language. Similarly, 0xfe and 0xff are not used by the language, and are reserved for internal use by the virtual machine.

Instructions fall into a number of broad groups:

  • Load and store (e.g. aload_0,istore)
  • Arithmetic and logic (e.g. ladd,fcmpl)
  • Type conversion (e.g. i2b,d2i)
  • Object creation and manipulation (new,putfield)
  • Operand stack management (e.g. swap,dup2)
  • Control transfer (e.g. ifeq,goto)
  • Method invocation and return (e.g. invokespecial,areturn)

There are also a few instructions for a number of more specialized tasks such as exception throwing, synchronization, etc.

Many instructions have prefixes and/or suffixes referring to the types of operands they operate on. These are as follows:

Prefix/Suffix Operand Type
i integer
l long
s short
b byte
c character
f float
d double
a reference

For example, "iadd" will add two integers, while "dadd" will add two doubles. The "const", "load", and "store" instructions may also take a suffix of the form "_n", where n is a number from 0-3 for "load" and "store". The maximum n for "const" differs by type.

The "const" instructions push a value of the specified type onto the stack. For example "iconst_5" will push an integer 5, while "dconst_1" will push a double 1. There is also an "aconst_null", which pushes "null". The n for the "load" and "store" instructions specifies the location in the variable table to load from or store to. The "aload_0" instruction pushes the object in variable 0 onto the stack (this is usually the "this" object). "istore_1" stores the integer on the top of the stack into variable 1. For variables with higher numbers the suffix is dropped and operators must be used .

Read more about this topic:  Java Bytecode

Famous quotes containing the word instructions:

    If we consider what happens in conversation, in reveries, in remorse, in times of passion, in surprises, in the instructions of dreams, wherein often we see ourselves in masquerade,—the droll disguises only magnifying and enhancing a real element, and forcing it on our distinct notice,—we shall catch many hints that will broaden and lighten into knowledge of the secret of nature.
    Ralph Waldo Emerson (1803–1882)

    They had supposed their formula was fixed.
    They had obeyed instructions to devise
    A type of cold, a type of hooded gaze.
    But when the Negroes came they were perplexed.
    These Negroes looked like men....
    Gwendolyn Brooks (b. 1917)

    Realizing that his time was nearly spent, he gave full oral instructions about his burial and the manner in which he wished to be remembered.... A few minutes later, feeling very tired, he left the room, remarking, ‘I have no disposition to leave this precious circle. I love to be here surrounded by my family and friends.’ Then he gave them his blessing and said, ‘I am ready to go and I wish you goodnight.’
    —For the State of New Hampshire, U.S. public relief program (1935-1943)