Subroutine In Computer Architecture YASH PAL, March 1, 2026March 1, 2026 Subroutine in Computer Architecture – In a computer program, the same piece of code might be written again in many different parts. The common code is written only once. A set of common instructions that can be used in a program many times is called a subroutine. Each time a subroutine is used in the main program, a branch is made to the beginning of the subroutine. The branch can be made from any part of the main program. It is necessary to store the return address somewhere in the computer for the subroutine to know where to return. In the basic computer, the link between the main program and a subroutine is the BSA instruction (branch and save return address). The first memory location of each subroutine serves as a link between the main program and the subroutine. The procedure for branching to a subroutine and returning to the main program is referred to as a subroutine linkage. The BSA instruction performs the call, and the BUN instruction performs the return. Let’s take an example program to demonstrate the use of subroutines. LocationORG 100/Main program100LDA X/Load X101BSA SH4/Branch to subroutine102STA X/Store shifted number103LDA Y/Load Y104BSA SHA/Branch to subroutine again105STA Y/Store shifted number106HLT107X,HEX 1234108Y,HEX 4321/Subroutine to shift left 4 times109SH4,HEX 0/Store return address here10ACIL/Circulate left once10BCIL10CCIL10DCIL/Circulate left fourth time10EAND MSK/Set AC (13-16) to zero10FBUN SH4 1/Return to main program110MSK,HEX FFF0/Mask operandEND When a subroutine is called, the main program must transfer the data it wishes the subroutine to work with. It is necessary for the subroutine to have access to data from the calling program and to return results to that program. The accumulator can be used for a single input parameter and a single output parameter. In computers with multiple processor registers, more parameters can be transferred this way. Another way to transfer data to a subroutine is through the memory. Data are often placed in memory locations following the call. They can also be placed in a block of storage. The first address of the block is then placed in the memory location following the call. In any case, the return address always gives the link information for transferring data between the main program and the subroutine. Computer System Architecture engineering subjects Computer System Architecture