© 2000 Scenix Semiconductor, Inc. All rights reserved. 111 SX User’s Manual Rev. 3.1 www.scenix.com Chapter 3 Instruction Set 3.6.41    RET Return from Subroutine Operation: program counter = top-of-stack Bits affected: none Opcode: 0000 0000 1100 Description: 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
RET. Cycles: 2 in “compatible” mode (SX18/20/28AC and SX18/20/28AC75 only), or 3 in “tur-
bo” mode
Example: page $000 ;set page of subroutine in STATUS reg. call addxy ;call subroutine addxy mov $0C,W ;use addxy subroutine results ... ;more of program (not shown) addxy ;subroutine address label mov W,$0E ;subroutine instructions start here add W,$0F ... ret ;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”
instruction.