baload

Load byte/boolean from array

Bytecode

Type Description
u1 baload opcode = 0x33 (51)

Stack ..., arrayref, index ==> ..., value

Description

Retrieves a byte from a byte array, expands it to an integer and places it on the operand stack. baload is also used to retrieve values from boolean arrays. In this case, arrayref is a reference to an array of booleans (see the newarray instruction) . If the entry at the given index is true, then the int 1 is pushed onto the stack, otherwise the int 0 is pushed onto the stack. In Sun's implementation, boolean arrays are actually stored as byte arrays, using one byte per boolean value. Other implementations might use packed arrays - or even int arrays - this is invisible to programs running on the JVM, which always use baload and bastore to access and store values in boolean arrays.

The arrayref must be of type reference and must refer to an array whose components are of type byte or of type boolean.

The index must be of type int.

Both arrayref and index are popped from the operand stack. The byte value in the component of the array at index is retrieved, sign-extended to an int value, and pushed onto the top of the operand stack.

Example

; This is like the Java code:
; byte x = arr[0];
; where x is local variable 2 and arr is a byte array in local variable 1
aload_1 ; load local variable 1 onto the stack
iconst_0 ; push the integer 0 onto the stack
baload ; retrieve the entry
istore_2 ; store the entry in local variable 2

Exceptions

NullPointerException - arrayref is null

ArrayIndexOutOfBoundsException -  index is < 0 or >= arrayref.length

Notes The baload instruction is used to load values from both byte and boolean arrays. In Sun's implementation of the Java Virtual Machine, boolean arrays   are implemented as arrays of 8-bit values. Other implementations may implement packed boolean arrays; the baload instruction of such implementations must be used to access those arrays.