© 2004 Microchip Technology Inc. DS70049C-page 2-9
Section 2. CPU
CPU
2
2.3.1 Software Stack Examples
The software stack is manipulated using the PUSH and POP instructions. The PUSH and POP
instructions are the equivalent of a MOV instruction with W15 used as the destination pointer. For
example, the contents of W0 can be pushed onto the stack by:
PUSH W0
This syntax is equivalent to:
MOV W0,[W15++]
The contents of the top-of-stack can be returned to W0 by:
POP W0
This syntax is equivalent to:
MOV [--W15],W0
Figure 2-4 through Figure 2-7 show examples of how the software stack is used. Figure 2-4
shows the software stack at device initialization. W15 has been initialized to 0x0800. Further-
more, this example assumes the values 0x5A5A and 0x3636 have been written to W0 and W1,
respectively. The stack is pushed for the first time in Figure 2-5 and the value contained in W0 is
copied to the stack. W15 is automatically updated to point to the next available stack location
(0x0802). In Figure 2-6, the contents of W1 are pushed onto the stack. In Figure 2-7, the stack
is popped and the top-of-stack value (previously pushed from W1) is written to W3.
Figure 2-4: Stack Pointer at Device Reset
Figure 2-5: Stack Pointer After the First PUSH Instruction
Figure 2-6: Stack Pointer After the Second PUSH Instruction
0x0000
0xFFFE
0x0800
W15
W15 = 0x0800
W0 = 0x5A5A
W1 = 0x3636
0x0000
0xFFFE
0x5A5A
W15 = 0x0802
W0 = 0x5A5A
W1 = 0x3636
0x0800
PUSH W0
0x0802
W15
0x0000
0xFFFE
0x5A5A
0x3636
W15 = 0x0804
W0 = 0x5A5A
W1 = 0x3636
0x0800
PUSH W1
0x0802
0x0804
W15