next up previous contents
Next: Unary Operators Up: Expressions Previous: Constant Values

Variable Values

To load the value of a variable of a primitive type on the operand stack, which is stored in an array of one element, you first have to push the reference to the array and the position of the element in the array on the stack. After that you can load the value from the array at the right position.

If the variable is a local variable, the code that does the above is:

 
 aload  index       		 load the  arrayref on the stack;

iconst_0 load the index in the array on the stack;

<t>aload load the value from the array on the stack.

The index of the aload instruction is the index of the local variable in the local variable table of the method.

The <t> of the <t>aload instruction is the letter for the appropriate type, where i is for type int, f for type float, c for char and b for type boolean, so you get one of the instructions iaload, faload, caload or baload.

If the variable is global, the getstatic instruction is used instead of the aload instruction. The getstatic instruction takes the index into the constant_pool[] of the CONSTANT_Fieldref_info entry describing the variable as its operands.



mark@bottom.xs4all.nl