HP 9100B Operating & Programming Manual page 105

Hide thumbs Also See for 9100B:
Table of Contents

Advertisement

PROGRAMMING THE 91008
PROGRAM KEYS- SUBROUTINES
When a subroutine is called the calculator 'remembers' the re-
turn-address; up to five return-addresses can be
'remember-
ed' at any one time. As soon as a return ts made from a
sub-
routine, the return-address ofthat subroutine ts 'forgotten'; the
calculator is now ready to remernher another
return-address.
ln the preceeding illustration the number of subroutines called,
du ring subroutine # 1, is (apparently) limited to four (#2
through #5); this is because the subroutines
(#
1 through
#5) are 'nested' to a depth of five. However, more subroutines
may be called du ring subroutine
#
1. For
example,
after the
return from #4, the return-address of #4 and #5 are
'tor-
gatten'; there is now room for two more subroutines to be
called.
ln summary:
1.
any number of subroutines can be used during a
program;
2.
any number of subroutines can be used during
a subroutine, however,
3.
no more than five subroutines can be used at
any one time during a
program.
The following is part of the program (on Page 97) which uses
a subroutine.
STEP
KEY
STEP
KEY
. . .
.
.
-
-
.
.
.
.
. .
. .
. . .
.
.
<+)17
t
(+)24
x~',
18
GO TO ( ) ( )
.
.
. .
.
. .
.
. .
19
•SUB•
I
RETURN
38
PAUSE
la
2
39
PAUSE
1b
4
3a
•SUB•
I
RETURN
1c
y:()
3b
• .& -
At step ( +) 1
b
the program branches to the subroutine starting
at address (
+
)24 and executes the instructions of the
sub-
routine; at step (
+
)3a the program branches back to address
(+)1c
and continues executing the program.
The following program illustrates the use of a subroutine; the
N! program (Page
88 ),
slightly alte red, is used as the
sub-
routlne.
This program calculates possible combinations (C) of n
objects,
taken k at a time.
For example, if a box contains (n) 15 different colared balls,
how many possible color combinations (C) are there if (k) 5
balls are selected (and then returned) at a time.
Answer
=
3,003
95

Advertisement

Table of Contents
loading

Table of Contents