Section 8: Subroutines; Subroutine Limits; Subroutine Usage - HP -11C Owner's Handbook Manual

Hide thumbs Also See for HP-11C:
Table of Contents

Advertisement

120
Section 8: Subroutines
Subroutine
Execution trans-
fers to line 000
and halts.
Execution trans-
fers back to main
program; pending
return status
cleared.
after the (RTN).
After a (GTO), the next [RTN]
causes execution to transfer to
line 000 and halt; after a [GSB], the next (RTN] causes
execution to transfer back to the main program and resume.
Subroutine Limits
A subroutine can call up another subroutine, and that subroutine
can call up yet another subroutine. This "subroutine nesting"—the
execution of a subroutine within a subroutine—is limited only by
the number of returns ([RTN]}) that can be held pending at any one
time in the HP-11C, Here is how the HP-11C operates with nested
subroutines.
Main Program
ret
ial
fea
i
a wwe
wee
Vev
wv
Section 8: Subroutines
121
The
calculator
can
return
back
to the main
program
from
subroutines that are nested four deep, as shown. If you attempt to
call a subroutine that is nested five levels deep, the calculator will
halt and display Error 5 when it encounters the instruction calling
the fifth subroutine level.
Note: While any one set of nested subroutines can be up to
four levels deep, there is no limit to the number of nested
subroutine sets or non-nested subroutines you can include
in a program.
Subroutine Usage
Example. Write a program for cal-
culating the average slope between
x, and xp on the graph shown, where
y=x?—sinx.
Solution: The average slope is given by the formula
Yo-¥1
_ (xg4— sin xg) —(x;? — sin x1)
XX
XQ
%y
Notice
that
the
solution
requires
two
computations
of the
expression x? ~ sin x (once for x = x, and again for x =x).
Since the solution includes an expression that must be repeated for
both values of x, we can create a subroutine to execute the
repetition and save space in program memory.

Advertisement

Table of Contents
loading

Table of Contents