You are on page 1of 6

Date: 25/8/2023

Module: Microprocessor and Microcontroller


Practical No.8
Title: Stack

1. Objective:
The stack is a group of memory locations in the R/W memory that is used for temporary
storage of binary information during the execution of a program. The starting memory
location of the stack is defined in the main program, and space is reserved, usually at the
high end of the memory map. The method of information storage resembles a stack of book.
In this practical, firstly we learn the instructions for using the stack. Next, we input several
simple programs including the above instructions, and check the results.

2. Theory:
Stack Instructions
Instructions Tasks Examples
LXI SP, 16-bit Load Stack Pointer LXI SP,4000H
PUSH B/D/H/PSW Store Register Pair on Stack PUSH D
Copy the contents of the specified register pair on
the stack. The stack pointer is decremented by 2.
The operand PSW represents Program Status
Word, meaning the contents of the accumulator
and the flags.
POP B/D/H/PSW Retrieve Register Pair from Stack POP H
Move the contents of the memory location
indicated by the stack pointer register. The stack
pointer is incremented by 2.

Simple PUSH and POP Instructions Register Contents


Memory A F
Location Mnemonics B C
2000 LXI SP,4000H D E
2003 LXI H,7AFFH H 7A FF L
2006 PUSH H SP 4000
2007 INX H
2008 POP H
2009 HLT

-1-
Register Contents Memory
A F
B C
D E PUSH H
H 7A FF L
SP 3FFE
FF 3FFE SP
7A 3FFF
X 4000 SP
Ta

Register Contents Memory


A F
B C
D E POP H
H 7A FF L
SP 4000
FF 3FFE SP
7A 3FFF Ta

X 4000 SP

Several PUSH and POP Instructions


Memory
Location Mnemonics Register Contents
2000 LXI SP,4000H A 7A Flags F
2003 LXI H,7AFFH B C
2006 LXI D,2C8DH D 2C 8D E
2009 MOV A,H H 7A FF L
200A PUSH H SP 4000
200B PUSH D
200C PUSH PSW

201F POP PSW


2010 POP D
2011 POP H

-2-
Initial Stack Pointer Memory Memory
Contents Contents Contents Address
4000 2000
Program
3FFF
PUSH H
3FFE
3FFD
PUSH D 2012
3FFC
3FFB
PUSH PSW
3FFA
(Flags) 3FFA SP
(A)
7A 3FFB
(E)
8D 3FFC
(D)
2C 3FFD
(L)
FF 3FFE
(H)
7A 3FFF
4000 SP
Ta
Stack Pointer Contents
After Each POP
Stack Instruction
Initial
Contents Instructions 3FFA Location
3FFA (Flags)
Task
POP PSW A 7A (Flags) F 3FFC
3FFB 7A Task
3FFC 8D
POP D D 2C 8D E 3FFE
3FFD 2C Task
3FFE FF
POP H H 7A FF L 4000
3FFF 7A
Task

3. Apparatus Required:
8085 Microprocessor Trainer Vinytics VMC-8501 1
Manual Vinytics VMC-850X User’s Manual 1

-3-
4. Procedure:
4.1 Simple PUSH and POP Instructions
Specify the contents of registers and memory as the following instructions are executed,
same as Practical No.5.
Memory Location
H L SP PC 3FFFH 3FFEH
Initial Contents
LXI SP,4000H
LXI H,7AFFH
PUSH H
INX H
POP H
HLT

(a) Assemble the instructions, and enter the Hex machine code on the microprocessor trainer,
starting with the memory address 2000H same as Practical No.1.
(b) Execute the program in Single Instructions (SI) mode as follows.

EXREG MEMC
RESET 2 0 0 0
SI NEXT

(c) Display the initial content of memory location 3FFFH as follows, and record it.

FILL REL MEMC


3 F F F
 EXMEM NEXT

STRNG
(d) By pressing -key, display the initial contents of memory location 3FFEH,
PRE

and record it.


(e) Display the initial content of Register H as follows, and record it.

FILL EXREG 8
SHIFT
 SI H

MEMC
(f) By pressing -key, display the initial contents of Registers L, Program Counter
NEXT

MSB & LSB (PCH & PCL), and Stack Pointer MSB & LSB (SPH & SPL), and record
them.

-4-
(g) Run the program further as follows.

FILL EXREG MEMC


SHIFT
 SI NEXT

(h) Repeat (c) to (g) till Program Counter is 200AH (PCH=20H & PCL=0AH).

4.2 Double PUSH and POP Instructions


Specify the contents of registers and memory as the following instructions are executed.
Memory Location
D E H L SP PC 3FFFH 3FFEH 3FFDH 3FFCH
Initial Contents
LXI SP,4000H
LXI H,7AFFH
LXI D,2C8DH
PUSH H
PUSH D
XCHG
POP D
POP H
HLT

5. Consideration [Question]:
(a) Read the following program and answer the questions given below.
Memory Location Mnemonics
2000 LXI SP,4000H
2003 LXI H,7AFFH
2006 LXI D,2C8DH
2009 LXI B,93E1H
200C PUSH H
200D PUSH B
200E PUSH D
200F MOV A,L

2020 POP H
2021 POP B
2022 POP D
2023 HLT

-5-
i. What is stored in the stack pointer register after the execution at the memory location
2000H?
ii. Specify the memory location and its contents of the stack where the first data byte
will be stored?
iii. What is stored in memory location 3FFEH when PUSH H (at memory location
200CH) is executed?
iv. After the execution of PUSH B (at memory location 200DH), what is the address in
the stack pointer register, and what is stored in its stack memory address?
v. After the execution of PUSH D (at memory location 200EH), what is the address in
the stack pointer register, and what is stored in its stack memory address?
vi. Specify the contents of register pair HL after the execution of POP H (at memory
location 2020H).
vii. Specify the contents of register pair BC after the execution of POP B (at memory
location 2021H).
viii. Specify the contents of register pair DE after the execution of POP D (at memory
location 2022H).
(b) Explain the function of the following program.
LXI SP,4000H
LXI H,0000H
PUSH H
POP PSW
HLT
(c) Explain the function of the following program.
LXI SP,4000H

PUSH B
PUSH D
POP B
POP D
HLT

-6-

You might also like