bastore

store in byte/boolean array

Bytecode

Type Description
u1 bastore opcode = 0x54 (84)

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

Description

Takes a 32-bit int from the stack, truncates it to an 8-bit signed byte, and stores it in an array of bytes. bastore is also used to store values in boolean arrays. In this case, arrayref is a reference to an array of booleans (see the newarray instruction) . If value is zero, false is stored at the given index in the array, otherwise true is stored at the given index. 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 and the value must both be of type int.

The arrayref, index, and value are popped from the operand stack. The int value is truncated to a byte and stored as the component of the array indexed by index.

Exceptions

NullPointerException - arrayref is null

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

Notes

The bastore instruction is used to store values into 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 bastore instruction of such implementations must be used to store into those arrays.