3.9.1.1 Stack Pointer Example

Figure 3-4 through Figure 3-7 show how the software stack is modified for the code snippet shown in Stack Pointer Usage. Figure 3-4 shows the software stack before the first PUSH has executed. Note that the SP has the initialized value of 0x4000. Furthermore, the example loads 0x5A5A and 0x3636 to W0 and W1, respectively. The stack is PUSHed for the first time in Figure 3-5 and the value contained in W0 is copied to TOS. W15 is automatically updated to point to the next available stack location and the new TOS is 0x4004. In Figure 3-6, the contents of W1 are PUSHed onto the stack and the new TOS becomes 0x4008. In Figure 3-7, the stack is POPped, which copies the last PUSHed value (W1) to W3. The SP is decremented during the POP operation and at the end of the example, the final TOS is 0x4004.

Figure 3-4. Stack Pointer Before the First PUSH
Figure 3-5. Stack Pointer After “PUSH.L W0” Instruction
Figure 3-6. Stack Pointer After “PUSH.L W1” Instruction
Figure 3-7. Stack Pointer After “POP.L W3” Instruction

Stack Pointer Usage

MOV		#0x5A5A, W0         ; Load W0 with 0x5A5A
MOV		#0x3636, W1		     ; Load W1 with 0x3636
PUSH.L		W0				; Push W0 to TOS
PUSH.L		W1				; Push W1 to TOS
POP.L		W3				; Pop TOS to W3