© 2000 Scenix Semiconductor, Inc. All rights reserved.
45
SX Users Manual Rev. 3.1
www.scenix.com
Chapter 2 Architecture
2.7 Stack
When a call instruction is executed, the full address of the instruction immediately following the
call instructions is pushed onto the program stack. Upon return from the subroutine, the full address
is popped from the stack and restored to the program counter, causing execution to resume with the
instruction immediately following the call instruction.
The stack is a last-in, first-out (LIFO) data buffer, 12 bits wide (11 bits wide for the SX18/20/28AC
and SX18/20/28AC75) and eight levels deep. The eight levels of the stack allow subroutines be nested,
one within another, up to eight levels deep.
For the SX18/20/28AC and SX18/20/28AC75 devices, in the default device configuration, the stack is
limited to two levels. In general, however, the stack should be configured to eight levels because there
is no reason to limit the stack size. This option is controlled by the STACKX bit in the FUSEX word
register (a register programmed at the same time as the program memory).
Table 2-8 Return-from-Subroutine/Interrupt Instructions
Option Bits
Description
RET
Return from Subroutine. This is an ordinary return from subroutine. It does not
affect any registers or bits.
RETP
Return from Subroutine Across Page Boundary. This instruction works like the
RET instruction, but also writes bits 11:9 of the return address (the address of the
instruction immediately following the CALL instruction) to the PA2:PA0 bits of
the STATUS register. This automatically configures the PA2:PA0 bits to select
the current page, allowing a subsequent same-page jump or call to be executed
without another page instruction.
RETW #lit
Return from Subroutine with Literal in W. This instruction works like the RET
instruction, except that it loads a literal value into W before returning from the
subroutine. A sequence of these instructions can be used in conjunction with a
PC-adjustment instruction to implement a data-lookup table.
RETI
Return from Interrupt. This instruction restores the program counter and the W,
STATUS, and FSR registers that were saved upon occurrence of the interrupt.
(Note that the program stack is not used for interrupt processing.)
RETIW
Return from Interrupt and Adjust RTCC with W. This instruction works like the
RETI instruction, but also adds W to the RTCC register. This can be used to
adjust the RTCC counter back to the value in contained upon occurrence of the
interrupt.