3.1 Some Definitions

An Oolong method body is a list of instructions. Each instruction is of the form

 mnemonic argument1 argument2 ... 

The mnemonic says what you want to do: push a variable, add integers, call a method, and so on.

The arguments to an instruction affect the way the instruction works. They answer questions like "Which variable should be pushed?" and "Which method should be called?" The arguments to an instruction are the same each time an instruction is performed. For example, the instruction

 aload 99    ; Push the local variable 99 onto the stack 

has a single argument: the number 99. When this instruction is executed, the JVM copies the contents of index 99 of the local variable array onto the stack. The contents of that local variable may be different each time the instruction is executed (which is why it's called a variable), but it will always be local variable 99 that is loaded.

The operands to an instruction come from the operand stack. Unlike arguments, the operands may be different each time. An example is the instruction

 iadd        ; Add the two integers on top of the stack 

This instruction takes the top two items of the stack, which should both be int values. These values are the operands to the iadd instruction. If the two previous instructions push the values 2 and 3 onto the stack, then iadd will pop them both and push 5.

The next time this instruction is encountered, the operands may be different. If the top of the stack is now 3 and 4, then the result of the iadd is 7.

The point here is to define the terms argument and operand, which will be used quite heavily in the next few chapters. Argument always refers to additional information after the mnemonic, which never changes as the program runs. Operand refers to the elements on the operand stack; these change as the program runs.



Programming for the Java Virtual Machine
Programming for the Javaв„ў Virtual Machine
ISBN: 0201309726
EAN: 2147483647
Year: 1998
Pages: 158
Authors: Joshua Engel

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net