The EVM does not provide subroutines as a primitive. Instead, calls must be synthesized by fetching and pushing the current program counter on the data stack and jumping to the subroutine address; returns must be synthesized by getting the return address to the top of stack and jumping back to it.
## Specification
##### `JUMPSUB`
Jumps to the address on top of the stack, which must be the offset of a `JUMPDEST`.
A program may `JUMPSUB` at most 1023 times without an intervening `RETURNSUB`. A program which executes `RETURNSUB` without no prior `BEGINSUB` will `STOP`.
The new operators proposed here are implemented by the following pseudocode, which in eight lines adds a return stack and cases for `JUMPSUB` and `RETURNSUB` to a simple loop-and-switch interpreter.
Execution of EVM bytecode begins with one value on the return stack—the size of the bytecode. The virtual byte of 0 at this offset is the EVM `STOP` opcode, so executing a `RETURNSUB` with no prior `JUMPSUB` executes a `STOP`. A `STOP` or `RETURN` ends the execution of the subroutine and the program.
Program flow analysis frameworks will need to be updated to allow for a new type of branch -`JUMPSUB` - and new type of branching - `RETURNSUB` - which will cause a jump to a destination which is a `JUMPSUB`, not a `JUMPDEST`.