prev next contents
goto

branch to address

Jasmin Syntax


    goto <label>
<label> is a label name. To define the location of the label, use the <label> name followed by a colon:

<label>:
<label> then becomes associated the address of the following instruction. Labels can only be assigned one location in a method. On the other hand, a single <label> can be the target of multiple branch instructions.

Stack

Before

After
...
...
Description

Causes execution to branch to the instruction at the address (pc + branchoffset), where pc is the address of the goto opcode in the bytecode and branchoffset is a 16-bit signed integer parameter that immediately follows the goto opcode in the bytecode. In Jasmin, branchoffset is computed for you using the address associated with <label>.

Example


;
; This is like the Java code:
;     while (true) { i++; }

Label:
   incr 1 1       ; Increment local variable 1 by 1
   goto Label     ; jump back to Label

Bytecode

Type

Description
u1
goto opcode = 0xA7 (167)
s2
branchoffset
See Also

goto_w, jsr, jsr_w

Notes

Addresses are measured in bytes from the start of the bytecode - i.e. address 0 is the first byte in the bytecode of the currently executing method. The maximum address in a method is 65535.


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