A subroutine is a set of common instructions that can be used in a program many times.
A subroutine consists of a self-contained sequence of instructions that carries out a given task.
Each time that a subroutine is used in the main part of the program, a branch is executed to the beginning of the subroutine.
After the subroutine has been executed, a branch is made back to the main program.
A branch can be made to the subroutine from any part of the main program.
Because branching to a subroutine and returning to the main program is such a common operation, all computers provide special instructions to facilitate subroutine entry and return. Program : LXI H, XX50H ; Set up HL as a pointer for the source memory LXI D, XX70H ; Set up DE as a pointer for the destination memory MVI B, 10H ; Set up B as byte counter NEXT : MOV A,M ; Get data byte from the source memory STAX D ; Store the data byte in destination memory INX H INX D ; Get ready to transfer next byte DCR B JNZ NEXT ; Go back to get next byte if byte counter ≠ 0 HLT
Discussion
Ask a question, share your thoughts or report an error.
Sign in to participate in the discussion.
Join the discussion