Stacks & Subroutines�Slides-7
Dr. Ritika
Department of Computer Application
The Stack
The Stack
LXI SP, FFFFH
Saving Information on the Stack
The PUSH Instruction
The POP Instruction
Operation of the Stack
LIFO
PUSH B
PUSH D
...
POP D
POP B
The PSW Register Pair
Cautions with PUSH and POP
Program to Reset and display Flags
Program to Reset and display Flags
Program to Reset and display Flags
Subroutines
Subroutines
The CALL Instruction
The CALL Instruction
The RTE Instruction
Illustrates the exchange of information between stack and Program Counter
Program Execution
CALL Execution
RET Execution
Passing Data to a Subroutine
RESTART, CONDITIONAL CALL & RETURN INSTRUCTIONS
RST Instruction
RESTART, CONDITIONAL CALL & RETURN INSTRUCTIONS
Conditional CALL
RESTART, CONDITIONAL CALL & RETURN INSTRUCTIONS
Conditional RETURN
A Proper Subroutine
Writing Subroutines
Write a Program that will display FF and 11 repeatedly on the seven segment display. Write a ‘delay’ subroutine and Call it as necessary.
C000: LXI SP, FFFF C003: MVI A, FF
C005: OUT 00 C007: CALL C014 C00A: MVI A, 11
C00C: OUT 00 C00E: CALL 1420 C011: JMP C003
Writing Subroutines
DELAY: C014: MVIB, FF
C016: MVIC, FF
C018: DCR C
C019: JNZ C018
C01C: DCR B
C01D: JNZ C016
C020: RET
Nesting Subroutines
Problem Statement
Problem Statement
Problem Statement
Problem Statement
Problem Statement