
DocID13284 Rev 2
551/564
UM0404
System programming
User stacks
User stacks provide the ability to create task specific data stacks and to off-load data from
the system stack. The user may push both byte and words onto a user stack, but is
responsible for using the appropriate instructions when popping data from the specific user
stack. No hardware detection of overflow or underflow of a user stack is provided. The
following addressing modes allow implementation of user stacks:
[– Rw], Rb or [– Rw], Rw
: Pre-decrement Indirect Addressing. Used to push one byte or
word onto a user stack. This mode is only available for MOV instructions and can specify
any GPR as the user stack pointer.
Rb, [Rw+] or Rw, [Rw+]
: Post-increment Index Register Indirect Addressing. Used to pop
one byte or word from user stack. This mode is available to most instructions with some
restrictions.
For MOV instructions, any word GPR can be used as user stack pointer.
For arithmetic, logical and compare instructions, only GPRs R0-R3 can be used.
Rb, [Rw+] or Rw, [Rw+]
: Post-increment Indirect Addressing. Used to pop one byte or word
from a user stack. This mode is only available for MOV instructions and can specify any
GPR as the user stack pointer.
27.2 Register
banking
Register banking provides the user with an extremely fast method to switch user context. A
single instruction cycle instruction saves the old bank and enters a new register bank. Each
register bank may assign up to 16 registers. Each register bank should be allocated during
coding based on the needs of each task. Once the internal memory has been partitioned
into a register bank space, internal stack space and a global internal memory area, each
bank pointer is then assigned. Thus, upon entry into a new task, the appropriate bank
pointer is used as the operand for the SCXT (switch context) instruction. Upon exit from a
task a simple POP instruction to the context pointer (CP) restores the previous task's
register bank.
27.3
Procedure call entry and exit
To support modular programming a procedure mechanism is provided to allow coding of
frequently used portions of code into subroutines. The CALL and RET instructions store and
restore the value of the instruction pointer (IP) on the system stack before and after a
subroutine is executed.
Procedures may be called conditionally with instructions CALLA or CALLI, or be called
unconditionally using instructions CALLR or CALLS.
Note:
Any data pushed onto the system stack during execution of the subroutine must be popped
before the RET instruction is executed.
Passing parameters on the system stack
Parameters may be passed via the system stack through PUSH instructions before the
subroutine is called, and POP instructions during execution of the subroutine. Base plus
offset indirect addressing also permits access to parameters without popping these
parameters from the stack during execution of the subroutine. Indirect addressing provides