DocID13284 Rev 2 549/564
UM0404 System programming
The virtual stack addresses are transformed to physical stack addresses by concatenating
the significant bit of the stack pointer register SP (see table) with the complementary most
significant bit of the upper limit of the physical stack area (00’FBFEh). This transformation is
done via hardware (see Figure 214).
The reset values (STKOV = FA00h, STKUN = FC00h, SP = FC00h, STKSZ = 000b) map
the virtual stack area directly to the physical stack area and allow using the internal system
stack without any changes, provided that the 256 word area is not exceeded.
Figure 214. Physical stack address generation
The following example demonstrates the circular stack mechanism which is also an effect of
this virtual stack mapping: First, register R1 is pushed onto the lowest physical stack
location according to the selected maximum stack size. With the following instruction,
register R2 will be pushed onto the highest physical stack location although the SP is
decremented by 2 as for the previous push operation.
The effect of the address transformation is that the physical stack addresses wrap around
from the end of the defined area to its beginning. When flushing and filling the internal stack,
1 0 1 b --- Reserved. Do not use this combination. ---
1 1 0 b --- Reserved. Do not use this combination. ---
1 1 1 b 1024 00’FDFEh...00’F600h (Note: No circular stack) SP.11...SP.0
MOV SP, #0F802h ; Set SP before last entry of physical stack of 256 Words
... ; (SP) = F802h: Physical stack address = FA02h
PUSH R1 ; (SP) = F800h: Physical stack address = FA00h
PUSH R2 ; (SP) = F7FEh: Physical stack address = FBFEh
Table 76. Stack size selection (continued)
(STKSZ)
Stack size
(words)
IRAM addresses (words)
of physical stack
Significant bit of
stack pointer SP
1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 0
1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 0
1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 0
1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 0
1 1 1 1 1 0 1 1 1 0 0 0 0 0 0 0
1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 0
1 1 1 1 1 0 1 1 1 0 0 0 0 0 0 0 1 1 1 1 1 0 1 0 0 0 0 0 0 0 0 0
1 1 1 1 1 0 1 1 0 1 1 1 1 1 1 0
1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 0
FBFEh
FB80h
FB80h
FBFEh
FB7Eh
FBFEh
FBFEh
64 Words 256 Words
F800h
FA00h
1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 0
FBFEh
F7FEh
FBFEh
(SP)
(SP)
Phys.A.
Phys.A.
Stack Size
After PUSH
After PUSH