EMAC PRIMER Instruction Manual page 57

Table of Contents

Advertisement

You can now see where the name "stack" comes from, data is "stacked" in memory with every PUSH instruction. Since the
stack grows down in memory it is possible for it to eventually overwrite your program, so you must be careful when using
the stack.
POP instructions work the opposite of PUSH instructions. For example, if a POP H instruction was executed after the
PUSH PSW in the previous example, then the data at memory address SP would be copied into the L register and the data
at memory address SP + 1 would be copied into the H register then 2 would be added to SP. In other words, the data that
was in the PSW when it was pushed on the stack will be copied into the HL register pair. Similarly if PUSH BC was
executed followed by POP HL, then B would be copied to H and C would be copied to L.
To demonstrate the way PUSH and POP works, load the program counter register with FFCB then load the following
program into memory, exactly as it is shown.
org
0ffc7h
push
psw
push
b
pop
psw
pop
b
db
0,0,0,0,0
db
0,0,0,0,0
ADDRESS
PC->
FFC7
FFC8
FFC9
FFCA
FFCB
FFCC
FFCD
FFCE
FFCF
FFD0
FFD1
FFD2
FFD3
SP->
FFD4
Load the program counter with FFC7 again and load the A register with 01, the flags register with 02, load BC with 0304
and do the following:
1) Examine the SP register which should be FFD4.
2) Examine the stack contents and they should be 0000. This is done the same way as examining a register.
Press the "func." key and then the "9/S.C." key and the stack contents will be displayed in the
"ADDRESS/REGISTER PAIR" displays. Remember that S.C. is not an 8085 internal register, it is just a way that
the MOS provides for viewing the two bytes on top of the stack.
3) Single step once at address FFC7. This pushes the PSW on the stack (the A register and flags).
4) If you examine SP then you will find that it is now FFD2 which is 2 less than before.
5) The stack contents will now be 0102 which is the value of the PSW that was pushed on the stack. Examine the
stack contents to verify this.
The listing below shows what the stack looks like now and the PC and SP registers are shown pointing to their respective
memory addresses.
; start program near top of stack
; put PSW on stack (A register and flags)
; put BC register pair on stack
; remove data from stack and put in PSW
; remove data from stack and put in BC
; there are zeros in the stack area so
; it will be in a known initial state
DATA
DESCRIPTION
F5
PUSH
C5
PUSH
F1
POP
C1
POP
00
00
00
00
00
00
00
00
00
00
(stack pointer is here)
PSW
B
PSW
B
57

Advertisement

Table of Contents
loading

Table of Contents