Stack and Subroutine in 8085 Microprocessor

Stack in 8085 Microprocessor:

The stack is a portion of RAM memory defined by the user for temporary storage and retrieval of data while executing a program. In an 8085 processor, the stack is created by loading a 16-bit address in the stack pointer. Upon reset, the stack pointer is cleared to zero. In an 8085 processor, for every write operation into the stack, the SP is automatically decremented by two, and for every read operation from the stack, the SP is automatically incremented by two.

Hence, data can be stored only in lower addresses from the address pointed by SP. Therefore, we can say that the SP holds the address at the top of the stack. All the RAM addresses higher than that pointed by the SP can be considered as occupied stack and all the RAM addresses lower than that pointed by the SP can be considered as empty stack as shown in Fig. 5.4. However, in practice only a few memory locations are needed for the stack.

Subroutine in 8085 Microprocessor:

Subroutine is a set of instructions that are used repeatedly in different locations of the program. Instead of repeating the same instructions several times, it can be combined into a subroutine that is called from various locations. A subroutine in Assembly language can exist anywhere in the code. 8085 microprocessor has two instructions to implement subroutines.

1. CALL: The CALL instruction is used to redirect program execution to a subroutine.

2. RET: The RET instruction is used to return the execution to the calling routine.