
C165UTAH
System Programming
Data Sheet
478
2001-02-23
Circular (virtual) Stack
This basic technique allows pushing until the overflow boundary of the internal stack is
reached. At this point a portion of the stacked data must be saved into external memory
to create space for further stack pushes. This is called “stack flushing”. When executing
a number of return or pop instructions, the upper boundary (since the stack empties
upward to higher memory locations) is reached. The entries that have been previously
saved in external memory must now be restored. This is called “stack filling”. Because
procedure call instructions do not continue to nest infinitely and call and return
instructions alternate, flushing and filling normally occurs very infrequently. If this is not
true for a given program environment, this technique should not be used because of the
overhead of flushing and filling.
The basic mechanism
is the transformation of the addresses of a virtual stack area,
controlled via registers SP, STKOV and STKUN, to a defined physical stack area within
the internal RAM via hardware. This virtual stack area covers all possible locations that
SP can point to, ie. 00’F000
H
through 00’FFFE
H
. STKOV and STKUN accept the same
4 KByte address range.
The size of the physical stack area within the internal RAM that effectively is used for
standard stack operations is defined via bitfield STKSZ in register SYSCON (see below).
The virtual stack addresses are transformed to physical stack addresses by
concatenating the significant bits of the stack pointer register SP (see table) with the
complementary most significant bits of the upper limit of the physical stack area
(00’FBFE
H
). This transformation is done via hardware (see figure below).
<STKSZ>
Stack Size
(Words)
256
Internal RAM Addresses (Words)
of Physical Stack
00’FBFE
H
...00’FA00
H
(Default after Reset)
00’FBFE
H
...00’FB00
H
00’FBFE
H
...00’FB80
H
00’FBFE
H
...00’FBC0
H
00’FBFE
H
...00’F800
H
(not for 1 Kbyte IRAM)
Reserved. Do not use this combination.
Significant Bits of
Stack Pointer SP
SP.8...SP.0
0 0 0
B
0 0 1
B
0 1 0
B
0 1 1
B
1 0 0
B
1 0 1
B
1 1 0
B
1 1 1
B
128
SP.7...SP.0
64
SP.6...SP.0
32
SP.5...SP.0
512
SP.9...SP.0
---
---
---
Reserved. Do not use this combination.
---
1024
00’FDFE
H
...00’FX00
H
(Note: No circular
stack)
00’FX00
H
represents the lower IRAM limit, ie.
1 KB: 00’FA00
H
, 2 KB: 00’F600
H
, 3 KB:
00’F200
H
SP.11...SP.0