English
Language : 

45111 Datasheet, PDF (166/184 Pages) List of Unclassifed Manufacturers – 14-DAY MONEY BACK GUARANTEE
15 Appendix E: SX Data Sheet
15.2.20 The Pop
When a return instruction is executed, the stack is popped. Specifically, the content of Stack 1 is copied
to the program counter and the content of each address in the stack is copied to the next higher level.
Stack 1 gets the value that was in Stack 2, etc. until Stack 7 is overwritten with the contents of Stack 8.
Consequently, the contents that were in Stack 8 are now duplicated in Stack 7.
PC<10:0>
Stack 1
Stack 2
Stack 3
Stack 4
Stack 5
Stack 6
Stack 7
Stack 8
Figure 35 - The Pop
15.2.21 Stack Overflow
As mentioned before, the stack can store up to eight return addresses (with Stack Extend on), or up to
two return addresses by default. With each push, the stack stores another address. When the stack is
full, the next push results in an overflow. The first time the stack is pushed into an overflow condition,
the first address pushed is lost forever. If the stack were to be pushed again, the second address pushed
would be lost also. A stack overflow condition inevitably leads to unintentional infinite loops or bizarre
looping actions in your program. Care should be taken to ensure a stack overflow does not ever occur.
15.2.22 Stack Underflow
When the stack is popped more times than it has been pushed, a stack underflow occurs. Since a stack
underflow causes unknown addresses to be stored in PC, a program may perform bizarre looping
actions, such as a jump to unused program memory.
15.2.23 Returns
There are five different return instructions available on the SX. The RET (return) instruction simply
pops the stack thereby setting the program counter to the instruction that followed the call. The RETW
(return with literal in w) instruction behaves the same way but loads W with the literal value specified.
RETP pops the stack and updates the page select bits to point to the page returned to. RETI pops the
Page 166 • SX-Key/Blitz Development System Manual 2.0 • Parallax, Inc.