SKYSPIN
In computers, a subroutine is a sequence of program instructions
that perform a specific task, packaged as a unit. This unit can then be
used in programs wherever that particular task have to be performed. A
subroutine is often coded so that it can be started (called) several
times and from several places during one execution of the program,
including from other subroutines, and then branch back (return) to the
next instruction after the call, once the subroutine’s task is done. It
is implemented by using Call and Return instructions. The different
types of subroutine instructions are
Unconditional Call instruction –
CALL address is the format for unconditional call instruction. After execution of this instruction program control is transferred to a sub-routine whose starting address is specified in the instruction. Value of PC (Program Counter) is transferred to the memory stack and value of SP (Stack Pointer) is decremented by 2.
Conditional Call instruction –
In these instructions program control is transferred to subroutine and value of PC is pushed into stack only if condition is satisfied.
Unconditional Return instruction –
RET is the instruction used to mark the end of sub-routine. It has no parameter. After execution of this instruction program control is transferred back to main program from where it had stopped. Value of PC (Program Counter) is retrieved from the memory stack and value of SP (Stack Pointer) is incremented by 2.
Conditional Return instruction –
By these instructions program control is transferred back to main program and value of PC is popped from stack only if condition is satisfied. There is no parameter for return instruction.
Advantages of Subroutine –
Subroutine in 8085
Unconditional Call instruction –
CALL address is the format for unconditional call instruction. After execution of this instruction program control is transferred to a sub-routine whose starting address is specified in the instruction. Value of PC (Program Counter) is transferred to the memory stack and value of SP (Stack Pointer) is decremented by 2.
Conditional Call instruction –
In these instructions program control is transferred to subroutine and value of PC is pushed into stack only if condition is satisfied.
Unconditional Return instruction –
RET is the instruction used to mark the end of sub-routine. It has no parameter. After execution of this instruction program control is transferred back to main program from where it had stopped. Value of PC (Program Counter) is retrieved from the memory stack and value of SP (Stack Pointer) is incremented by 2.
Conditional Return instruction –
By these instructions program control is transferred back to main program and value of PC is popped from stack only if condition is satisfied. There is no parameter for return instruction.
Advantages of Subroutine –
- Decomposing a complex programming task into simpler steps.
- Reducing duplicate code within a program.
- Enabling reuse of code across multiple programs.
- Improving tractability or makes debugging of a program easy.
0 Comments