© 2000 Scenix Semiconductor, Inc. All rights reserved. 115 SX User’s Manual Rev. 3.1 www.scenix.com Chapter 3 Instruction Set 3.6.45    RETW lit Return from Subroutine with Literal in W Operation: W = lit program counter = top-of-stack Bits affected: none Opcode: 1000 kkkk kkkk Description: This instruction causes a return from a subroutine and also puts an 8-bit literal value
into W. It pops the 12-bit value previously stored on the stack and loads that value
into the program counter. This causes the program to jump to the instruction imme-
diately following the “call” instruction that called the subroutine.
You can use multiple “RETW lit” instructions to implement a data lookup table. Cycles: 2 in “compatible” mode (SX18/20/28AC and SX18/20/28AC75 only), or 3 in “tur-
bo” mode
Example: mov  W,$0A   ;load W with value to be squared (0-7)
call square  ;call lookup-table subroutine
mov  $0B,W   ;use subroutine results (in W)
;more of program (not shown) square                    ;subroutine entry point
and  W,#$07  ;ensure that W is less than 8
add  $02,W   ;add W to PC to jump to applicable retw
retw 0
;0 squared = 0, beginning of data table retw 1 ;1 squared = 1 retw 4 ;2 squared = 4 retw 9 ;3 squared = 9 retw 16 ;4 squared = 16 retw 25 ;5 squared = 25 retw 36 ;6 squared = 36 retw 49 ;7 squared = 49, end of data table The “square” subroutine calculates the square of W and returns the result in W. To
use the subroutine, the program first loads W with the value to be squared, which
must be a value from 0 to 7. The subroutine adds the contents of W to the program
counter  (the  PC  register  at  address  02h),  which  advances  the  program  to  the
applicable “RETW lit” instruction. The “RETW lit” instruction returns from the
subroutine with the appropriate result in W.