Stacks and Subroutine
Stacks and Subroutine
AND
SUBROUTINES
BY-
VISHWAS
VITOBHA
DEEKSHA
AKHILA
MAHESHBABU
THE STACK
The stack is an area of memory identified by the
programmer for temporary storage of
information.
PUSH
POP
XTHL
SPHL
PUSH
Eg - PUSH B
B C
50
40 20
00 FFFA
FFFB
FFFC
00 FFFD SP
40 SP
FFFE
FFFF SP
POP
Eg – POP B
B C
50
40 20
00 FFFA
FFFB
FFFC
20 FFFD SP
50 FFFE SP
FFFF SP
SPHL
20 20
H
SPHL SP
L
50 50
XTHL
XTHL
H L
40
40
50 00
00
20 FFFA
FFFB
FFFC
00
20 FFFD
40
50 FFFE
FFFF
Subroutines
A subroutine is a group of instructions that will
be used repeatedly in different locations of the
program.
◦ Rather than repeat the same instructions several times,
they can be grouped into a subroutine that is called
from the different locations.
Main
program
Sub
routine
Subroutines
The 8085 has two instructions for dealing
with subroutines.
◦ The CALL instruction is used to redirect
program execution to the subroutine.
◦ The RET instruction is used to return the
execution to the calling routine.
18
The CALL Instruction
CALL 4000H
PC
50
40 20
00 FFFA
FFFB
FFFC
20 FFFD SP
50 FFFE SP
FFFF SP
The RET Instruction
RET
PC
50
40 20
00 FFFA
FFFB
FFFC
20 FFFD SP
50 FFFE SP
FFFF SP
4000 MVI C,03 4050 MOV A,C
4001 MVI B,02 4051 ADD B
4002 CALL 4050 4052 RET
4003 RST1
PC
40
40
40 51
02
010352
50
03 FFFA
FFFB
FFFC
03 FFFD SP
40 FFFE SP
FFFF SP