A subroutine is a set of instructions that will be used repeatedly in different locations of the program. Instead of repeating the same instructions several times, they can be combined into a subroutine that is called from various locations. A subroutine in Assembly language can exist anywhere in the code. However, It is a common practice to separate subroutines from the main program.

The 8085 microprocessor has two instructions to implement subroutines. The CALL
instruction is used to redirect program execution to a subroutine. The RET
instruction is used to return the execution to the calling routine. They are described in the following table.
MNEMONIC | DESCRIPTION |
---|---|
CALL 16-bit address | 3-byte instruction. Jumps unconditionally to the memory location specified. |
RET | 1-byte instruction. Unconditionally returns from the subroutine. |
When the CALL
instruction has been executed the contents of the program counter is saved to the top of the stack. This return address is retrieved from the stack when the RET
instruction is executed.