Honors Computer Systems Organization (Prof. Grishman)
Additional notes on array operations
iaload: before execution, stack should contain array reference
(second element on stack) and index (top element on stack); iaload
removes these and places value of array element on stack
iastore: before execution, stack should contain array reference
(third element on stack), index (second element on stack), and value to
store (top element on stack); iastore removes all three
for both operations, if index is out of range, an ArrayIndexOutOfBoundsException
is thrown; this can be caught by try/catch statements
Passing Objects as Arguments
The type for an object is
If the object contains public fields, these can be accessed by
getfield class/field type
(which expects the object reference on top of the stack, and replaces it
by the value of the field) and set by
putfield class/field type
(which expects the object reference as the second element on the stack
and the value to store on top of the stack, and removes both from the stack).
When a new object is constructed (by new in Java), an instance initialization
method for that class is invoked. This method has the name <init>
and does not return a value (its return type is void, V).
The object is passed as the first argument to the method (in local
The instance initialization method should call the <init> method
for its superclass, using the invokespecial operation, so a typical
<init> would look like
.class public Blah
If fields need to be initialized, this is done just before the return.
.method public <init>()V
When a non-static method is invoked, the object is passed as the first
argument (in local variable 0) and the other arguments in local variables
1, 2, ... .