Download C164CI - USBid

Transcript
System Programming
C164CI
22.1 Stack Operations
The C164CI supports two types of stacks. The system stack is used implicitly by the controller and
is located in the internal RAM. The user stack provides stack access to the user in either the internal
or external memory. Both stack types grow from high memory addresses to low memory addresses.
Internal System Stack
A system stack is provided to store return vectors, segment pointers, and processor status for
procedures and interrupt routines. A system register, SP, points to the top of the stack. This pointer
is decremented when data is pushed onto the stack, and incremented when data is popped.
The internal system stack can also be used to temporarily store data or pass it between subroutines
or tasks. Instructions are provided to push or pop registers on/from the system stack. However, in
most cases the register banking scheme provides the best performance for passing data between
multiple tasks.
Note: The system stack allows the storage of words only. Bytes must either be converted to words
or the respective other byte must be disregarded.
Register SP can only be loaded with even byte addresses (The LSB of SP is always ’0’).
Detection of stack overflow/underflow is supported by two registers, STKOV (Stack Overflow
Pointer) and STKUN (Stack Underflow Pointer). Specific system traps (Stack Overflow trap, Stack
Underflow trap) will be entered whenever the SP reaches either boundary specified in these
registers.
The contents of the stack pointer are compared to the contents of the overflow register, whenever
the SP is DECREMENTED either by a CALL, PUSH or SUB instruction. An overflow trap will be
entered, when the SP value is less than the value in the stack overflow register.
The contents of the stack pointer are compared to the contents of the underflow register, whenever
the SP is INCREMENTED either by a RET, POP or ADD instruction. An underflow trap will be
entered, when the SP value is greater than the value in the stack underflow register.
Note: When a value is MOVED into the stack pointer, NO check against the overflow/underflow
registers is performed.
In many cases the user will place a software reset instruction (SRST) into the stack underflow and
overflow trap service routines. This is an easy approach, which does not require special
programming. However, this approach assumes that the defined internal stack is sufficient for the
current software and that exceeding its upper or lower boundary represents a fatal error.
It is also possible to use the stack underflow and stack overflow traps to cache portions of a larger
external stack. Only the portion of the system stack currently being used is placed into the internal
memory, thus allowing a greater portion of the internal RAM to be used for program, data or register
banking. This approach assumes no error but requires a set of control routines (see below).
Semiconductor Group
22-4
Version 1.0, 11.97