49.

prev next contents
baload

retrieve byte/boolean from array

Jasmin Syntax
     baload 
Stack

Before

After
index
value
arrayref
...
...
...
Description

Retrieves a byte from a byte array, expands it to an integer and places it on the operand stack. arrayref is a reference to an array of bytes. index is an int. The arrayref and index are removed from the stack, and the 8-bit signed byte at the given index in the array is retrieved, sign-extended to a 32-bit int, and pushed onto the 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.

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

Bytecode

Type

Description
u1
baload opcode = 0x33 (51)
See Also

iaload, laload, faload, daload, aaload, caload, saload, iastore, lastore, fastore, dastore, aastore, bastore, castore, sastore, newarray


prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine
Java Virtual Machine (Java Series)
ISBN: 1565921941
EAN: 2147483647
Year: 1996
Pages: 171

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net