Explain stack and subroutine with suitable example.
Stack :
A Stack is similar to an array. It is a collection of a memory location that is used to store temporary information of program during execution.
The starting memory location is known as the top of the stack which defines how much space is reserved at the high end of memory.
Ex. LXI SP , 0008;
In stack we can perform two operation PUSH and POP.
PUSH : first decrement stack pointer and then store content into a memory location. Ex. PUSH H;
POP : to copy content of stack pointer into specified register pair and then increment the stack pointer. Ex. POP H;
Subroutine :
It is a subtask of the program which is repeated occurrence.
In the program we can write subroutine at anywhere.
The main advantage of subroutine are rather than repeat the same instruction many times they can write into the subroutine.
It stored from a different memory location.
CALL and RET instruction used for to call subroutine and to return from subroutine.
Ex. CALL 2030H
Follow Us