
#
User
’
s Manual
20-5
1999-08
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).
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, i.e. 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).
Table 20-2
STKSZ
Circular Stack Address Transformation
Stack Size
(Words)
of Physical Stack
256
00
’
FBFE
H
...00
’
FA00
H
(Default after Reset)
128
00
’
FBFE
H
...00
’
FB00
H
64
00
’
FBFE
H
...00
’
FB80
H
32
00
’
FBFE
H
...00
’
FBC0
H
512
00
’
FBFE
H
...00
’
F800
H
(not for 1KByte IRAM)
---
Reserved. Do not use this combination.
---
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, i.e.
1 KB: 00
’
FA00
H
, 2 KB: 00
’
F600
H
,
3 KB: 00
’
F200
H
Internal RAM Addresses (Words)
Significant Bits
of Stack Ptr. SP
SP.8...SP.0
SP.7...SP.0
SP.6...SP.0
SP.5...SP.0
SP.9...SP.0
---
---
SP.11...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