
C161U
System Programming
Data Sheet
402
2001-04-19
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).
The reset values (STKOV=FA00
H
, STKUN=FC00
H
, SP=FC00
H
, STKSZ=000
B
) 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 122
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.
MOV
SP, #0F802H
;Set SP before last entry...
;...of physical stack of 256 words
...
;(SP)=F802H: Physical stack addr.=FA02H
PUSH
R1
;(SP)=F800H: Physical stack addr.=FA00H
PUSH
R2
;(SP)=F7FEH: Physical stack addr.=FBFEH
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
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 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 1 1 1 1 1 1 1 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
FBFE
H
FB80
H
FB80
H
FBFE
H
FB7E
H
FBFE
H
FBFE
H
64 words
256 words
F800
H
1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0
FA00
H
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
FBFE
H
F7FE
H
FBFE
H
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
<SP>
<SP>
Phys.A.
Phys.A.
Stack Size
After PUSH
After PUSH