Return from subroutine
Bytecode
For local variable numbers in the range 0-255, use:
Type | Description |
u1 | ret opcode = 0xA9 (169) |
u1 | <varnum> |
There is also a wide format for this instruction, which supports access to all local variables from 0 to 65535:
Type | Description |
u1 | wide opcode = 0xC4 (196) |
u1 | ret opcode = 0xA9 (169) |
u2 | <varnum> |
ret is used to return from a subroutine that was invoked by jsr or jsr_w. It takes a single parameter, <varnum>, an unsigned integer which local variable is holding the returnAddress for this subroutine. Execution continues at the address stored in that local variable.
Return addresses are left on the stack by the jsr and jsr_w instructions. Methods are expected to immediately store the return address in a local variable, ready for use with ret.
The ret instruction should not be confused with the return instruction. A return instruction returns control from a Java method to its invoker, without passing any value back to the invoker.