aload

Retrieve object reference from the local variable

Bytecode

To access to local variables in the range 0-255, use:

Type Description
u1 aload opcode = 0x19 (25)
u1 <varnum>

The aload opcode can be used in conjunction with the wide instruction to access a local variable using a two-byte unsigned index. This approach supports access to all local variables from 0 to 65535:

Type Description
u1 wide opcode = 0xC4 (196)
u1 aload opcode = 0x19 (25)
u2 <varnum>

Stack ... ==> ..., objectref

Description

Retrieves an object reference from a local variable and pushes it onto the operand stack.

<varnum> must be a valid local variable number in the current frame. The local variable at <varnum> must contain a reference.

The aload instruction takes <varnum>, which indicates which local variable to retrieve. The object reference in that local variable is retrieved and placed on the stack.

Example

aload 1 ;     push object reference in local variable 1 onto the stack

Notes

If you use astore to store a returnAddress in a local variable, you cannot then use aload to retrieve the value of that local variable. This asymmetry with the astore instruction is intentional. Instead, if a local variable holds a returnAddress, your only choices are to (1) use ret to return to that address, or (2) use one of the store instructions to store some other value in the local variable.