© 2000 Scenix Semiconductor, Inc. All rights reserved.
SX Users Manual Rev. 3.1
Chapter 3 Instruction Set
Return from Subroutine
program counter = top-of-stack
0000 0000 1100
This instruction causes a return from a subroutine. It pops the 12-bit value previous-
ly stored on the stack and restores that value to the program counter. This causes the
program to jump to the instruction immediately following the call instruction that
called the subroutine.
It is not necessary to set the PA2:PA0 bits in the STATUS register in order to return
to the correct place in the program. This is because the full 12-bit program address
is restored from the stack. The ret instruction does not use (and does not affect)
the PA2:PA0 bits. It also does not affect the W register.
If you want to automatically configure the PA2:PA0 bits to select the current page
(the page of the instruction following the call instruction), use RETP instead of
2 in compatible mode (SX18/20/28AC and SX18/20/28AC75 only), or 3 in tur-
;set page of subroutine in STATUS reg.
;call subroutine addxy
;use addxy subroutine results
;more of program (not shown)
;subroutine address label
;subroutine instructions start here
;return from subroutine
The call instruction in this example calls a subroutine called addxy. When the
call instruction is executed, the address of the following instruction (the mov
$0C,W instruction) is pushed onto the stack and the program jumps to the addxy
routine. When the ret instruction is executed, the saved program address is
popped from the stack and restored to the program counter, which causes the
program to continue with the instruction immediately following the call