S
un
pl
us
IT
C
on
fid
en
tia
l
F
or
A
D
D
In
te
rn
at
io
na
l L
im
ite
d
U
se
O
nl
y
CPU6502 Instruction Manual v2.1
Sunplus reserves the rights to change this documentation without prior notice.
09/13/2005
11
Stack Pointer (SP)
Stack Pointer is a pointer which usually points to an available location where can be stored
pushed data. Normally, stack pointer is extended from FF to 00 in CPU 12. When data is
pushed onto stack, stack pointer will decrease by 1. When data is pulled (popped) from stack,
stack pointer is increased by 1.
First of all, a data 0ABH is pushed onto stack; then, the stack pointer points to the address
location $FE. Second, a data of 0CDH is pushed onto stack and the stack pointer then points
to the address location $FD. Third, a data of 0EFH is pushed onto stack and the stack
pointer is now pointing to the address location $FC.
In the pop activity, the stack pointer will be increased by 1 first; then stack pops the value of
0EFH. The stack pointer is now pointing to the address location $FD. When pop acts again,
stack pointer will be increased by 1 again; then pops the value of 0CDH. At this moment, the
stack pointer is pointing to the address location $FE. Finally, the stack pointer is increased by
1 and pops the value of 0ABH. Now, the stack pointer is pointing to the original address
location $FF. Note that if stack now pops again, the stack pointer will point to location $00.
This is an illegal stack activity since the bottom of stack is $FF.
SP-->FC
SP-->$FD
EF
SP-->$FE
CD
CD
AB
AB
AB
Stack Pointer, Push
Push AB
Push CD
Push EF
SP-->$FD
CD
SP-->$FE
AB
SP-->$FF
Stack Pointer, Pop
POP EF
POP CD
POP AB
AB