8085: Subroutine - Stack (Part 1)
8085: Subroutine - Stack (Part 1)
Concept of Stack
Function of stack to store and retrieve the data quickly from internal RAM.
The stack is an area of memory identified by the programmer for temporary storage of
information.
The stack is a LIFO structure.
– Last In First Out.
The stack normally grows backwards into memory.
– In other words, the programmer defines the bottom of the stack and the
stack grows up into reducing address range.
2
Microprocessor: 8085A
Subroutine Instruction-Stack
Concept of Stack
Given that the stack grows backwards into memory, it is customary to place the bottom of the stack at the
end of memory to keep it as far away from user programs as possible.
In the 8085, the stack is defined by setting the SP (Stack Pointer) register.
LXI SP, FFFFH
This sets the Stack Pointer to location FFFFH (end of memory for the 8085).
3
Microprocessor: 8085A
Subroutine Instruction-Stack
Concept of Stack
Information is saved on the stack by PUSHing it on.
– It is retrieved from the stack by POPing it off.
The 8085 provides two instructions: PUSH and POP for storing information on the stack and retrieving it
back.
– Both PUSH and POP work with register pairs ONLY.
4
Microprocessor: 8085A
Subroutine Instruction-Stack
Operation of Stack
5
Microprocessor: 8085A
Subroutine Instruction-Stack
6
Microprocessor: 8085A
Subroutine Instruction-Stack
7
Microprocessor: 8085A
Subroutine Instruction-Stack
LIFO
8
Microprocessor: 8085A
Subroutine Instruction-Stack
The PSW Register Pair
9
Microprocessor: 8085A
Subroutine Instruction-Stack
10
Microprocessor: 8085A
Subroutine Instruction-Stack
11
Microprocessor: 8085A
Subroutine Instruction-Stack
12
Microprocessor: 8085A
Subroutine Instruction-Stack
13
Microprocessor: 8085A
Subroutine Instruction-Stack
14
Microprocessor: 8085A
Subroutine Instruction-Stack
CALL Instruction
15
Microprocessor: 8085A
Subroutine Instruction-Stack
RET (1 Byte Instruction)
16
Microprocessor: 8085A
Subroutine Instruction-Stack
Conditional CALL and RTE Instructions
17
Thank You
18