j (jump) instruction or the
b (branch) instruction.
right is a sketch of what you can do with
(The same could be done with the
If the main routine needs to start up ("to call")
sub it can jump to
it with a
At the end of the subroutine, control can
be returned with another
The subroutine returns to a statement in
The subroutine is
called at just one point in
and it returns to an address a few instructions after
The subroutine is only used once
main program because it
always returns to the same location.
(You could write some tricky code to overcome
But it is much better to follow a subroutine linkage
convention such as is about to be discussed.)
A subroutine call is when a main routine (or other routine) passes control to a subroutine. The main routine is said to be the CALLER and the subroutine is said to be the CALLEE. A return from a subroutine is when a subroutine passes control back to its CALLER. When a CALLEE finishes execution it nearly always returns control to its CALLER.
Is it normal that a subroutine can be used in only one place in a program?