Subroutines and the Use of the Stack

J. C. Cluley · 1987

When planning programs we generally find that there are some small tasks which need to be performed frequently and if the instructions for these are written out in full each time they are needed the program becomes large and unwieldy. Much time and program space could be saved if it were possible to write the program for each task once only, and execute it repeatedly when required. Since this is such a frequent requirement, all microprocessors make provision for doing so. The program for each task is arranged as a Subroutine and stored outside the normal sequence of the main program. The subroutine is a normal segment of program but in order that the computer can return to the main program after executing it, the subroutine must end with a special Return from Subroutine (RTS or RET) instruction.

Read the paper · More papers on PaperTik