English
Language : 

C164CM_2 Datasheet, PDF (425/470 Pages) Infineon Technologies AG – 16-Bit Single-Chip Microcontroller
C164CM/C164SM
Derivatives
System Programming
22.1
Stack Operations
The C164CM supports two types of stacks: the system stack and the user stack. 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 Stack Pointer 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 be loaded with even byte addresses only (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.
User’s Manual
22-4
V1.0, 2002-02