[go: up one dir, main page]

0% found this document useful (0 votes)
77 views23 pages

Stacks and Subroutine

The document discusses stacks and subroutines in assembly language. It describes the stack as an area of memory used for temporary storage of information in a LIFO structure. It explains the PUSH, POP, XTHL and SPHL instructions for manipulating the stack. It also describes subroutines as groups of instructions that can be called from different parts of the main program using the CALL instruction and will return using RET.

Uploaded by

sirisha_cse
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views23 pages

Stacks and Subroutine

The document discusses stacks and subroutines in assembly language. It describes the stack as an area of memory used for temporary storage of information in a LIFO structure. It explains the PUSH, POP, XTHL and SPHL instructions for manipulating the stack. It also describes subroutines as groups of instructions that can be called from different parts of the main program using the CALL instruction and will return using RET.

Uploaded by

sirisha_cse
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 23

STACKS

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.

 It is a LIFO structure that normally grows


backwards into memory.

 The Size of the stack is limited only by the


available memory

 The beginning of the stack is defined in the


program by using the instruction LXI SP.
THE STACK

 The stack is initialized at the highest available


memory location to prevent program from being
destroyed by stack information.

 The stack pointer tracks the storage and


retrieval of the information.
STACK INSTRUCTIONS

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.

In Assembly language, a subroutine can exist


anywhere in the code.
◦ However, it is customary to place subroutines
separately from the main program.
SUB ROUTINE

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

You might also like