Jump and Flow Control

OpcodeActionDescription
RETfs--
(top of stack) -> PC
Will return back to the caller.This will POP the address from the stack.This will pop the value of R0 off the stack and jump to it.Note that trying to jump to an address outside of memory will not work, as the address is ANDed with 0x1ffe before being put into PC. Attempting to RETurn with an empty stack will cause an error to be generated.
RET Zif Z = 1, RETWill return back to the caller if the Z flag is set.If Z is clear, execution continues instead.
RET NZif Z = 0, RETWill return back to the caller if the Z flag is clear.If Z is set, execution continues instead.
RET Cif C = 1, RETWill return back to the caller if the C flag is set.If C is clear, execution continues instead.
RET NCif C = 0, RETWill return back to the caller if the C flag is clear.If C is set, execution continues instead.
JP nnnnPC ← n*2This is unconditional and will jump every time.The Immediate value is shifted by 1 and will always be a even PC address.
JP Z, nnnnif Z = 1
PC ← n*2
Will jump only if the Z flag is set.If Z is clear, execution continues instead.
JP NZ, nnnnif Z = 0
PC ← n*2
Will jump only if the Z flag is clear.If Z is set, execution continues instead.
JP C, nnnnif C = 1
PC ← n*2
Will jump only if the C flag is set.If C is clear, execution continues instead.
JP NC, nnnnif C = 0
PC ← n*2
Will jump only if the C flag is clear.If C is set, execution continues instead.
CALL nnnnif Z = 1
(top of stack) ← PC
Stack Counter++
PC ← n*2
Jumps to a subroutine. The address of the NEXT instruction after CALL is pushed onto the stack, then the address of the CALL is jumped to.Execution then continues at the new address.An RET instruction can then be used to pop the saved address off the stack and return from the subroutine when the subroutine is finished.
CALL Z, nnnnif Z = 1
(top of stack) ← PC
Stack Counter++
PC ← n*2
Will call only if the Z flag is set.If Z is clear, execution continues instead.
CALL NZ, nnnnif Z = 0
(top of stack) ← PC
Stack Counter++
PC ← n*2
Will call only if the Z flag is clear.If Z is set, execution continues instead.
CALL C, nnnnif C = 1
(top of stack) ← PC
Stack Counter++
PC ← n*2
Will call only if the C flag is set.If C is clear, execution continues instead.
CALL NC, nnnnif C = 0
(top of stack) ← PC
Stack Counter++
PC ← n*2
Will call only if the C flag is clear.If C is set, execution continues instead.