The stack in an 8085 can be described as a reserved area of the memory in the R/W memory where we can store temporary information. It is a shared resource as it can be shared by the microprocessor and the programmer. Programmers use the stack to store data and the microprocessors use the stack to execute subroutines.
The 8085 has a 16-bit register known as the Stack Pointer. The function of the stack pointer is to hold the starting address of the stack. This address can be decided by the programmer.
The stack operates on the Last In, First Out (LIFO) principle. The location of the most recent data on the stack is known as the TOP of the stack. The stack pointer always points to the top of the stack. Contents can be stored in the stack using the
PUSH instruction and can restore the contents by using the instruction
|LXI SP, 16-bit||Load the stack pointer register with a 16-bit address.|
|PUSH Rp||Copies the contents of the specified register pair on the stack|
|POP Rp||Copies the contents of the top two memory locations of the stack into the specified register pair.|
PUSH and POP Operation in 8085
This is a 1-byte instruction. This instruction copies the contents of the specified register pair on the stack as described below:
- The stack pointer is decremented and the contents of the higher-order register are copied to the location shown by the stack pointer register.
- The stack pointer is again decremented and the contents of the low-order register are copied to that location.
This is a 1-byte instruction. This instruction copies the contents of the top two memory locations of the stack into the specified register pair.
- First, the contents of the memory location indicated by the stack pointer register are copied into the low-order register and then the stack pointer register is incremented by 1.
- The contents of the next memory location are copied into the high-order register and the stack pointer register is again incremented by 1.
LXI SP,2099H LXI H, 42F2H PUSH H Delay Counter POP H
- The instruction
LXI SP, 2099Hwill initialize the stack pointer with the address of 2099H.
LXI H, 42F2Hwill initialize or load HL register pair with
H = 42and
L = F2.
- After the execution of
PUSH Hinstruction the stack pointer is decreased by one to
2098Hand the contents of the H register are copied to memory location
- The stack pointer is again decreased by one to
2097Hand the contents of the L register are copied to memory location
- After the execution of
POP Hinstruction, the contents of the top of the stack location shown by the stack pointer are copied in the L register and the stack pointer is increased by one to
- The contents of the top of the stack are copied in the H register and the stack pointer is increased by one.
- The contents of the memory locations
2098Hare not destroyed until some other data bytes are stored in these locations.