next up previous contents
Next: Procedure and Function Up: Statements Previous: Boolean Operators

Assignments

Now the expressions are done, assignment statements are pretty easy. As we have all the variables stored in arrays, we have to generate code that loads the reference to the array and the index on the operand stack. After the code for the expression is generated that loads the value of the expression on the stack, the instruction to store the value in the array has to be generated.

If the variable to assign to is a local variable, the code for an assignment is:

 
 aload  loc_index  		 load the  arrayref in local variable 
loc_index on the stack;

iconst_0 load the index in the array on the stack;

(code to load the value of the expression on the stack)

<t>astore store the value of the expression in the array.

The <t>astore instruction stores the value in the array, where <t> is the letter for the type of the array, where i stands for int, f for float, c for char and b for boolean.

If the variable to assign to is global, the getstatic instruction is used instead of the aload instruction.



mark@bottom.xs4all.nl