Home > HP > Calculator > HP 15c Manual

HP 15c Manual

Here you can view all the pages of manual HP 15c Manual. The HP manuals for Calculator are available online for free. You can easily download all the documents as PDF.

Page 101

 
101 
Section 9 
Subroutines 
When  the same set  of  instructions  needs  to  be  used  at  more  than  one  point 
in a  program,  memory  space  can be  conserved by storing those  instructions 
as a single subroutine. 
The Mechanics 
Go To Subroutine and Return 
The G (go to subroutine) instruction is executed in the same way as the 
t branch,  with  one  major  difference:  it  establishes  a pending  return 
condition. G label, like t label,* transfers program execution to the 
line with the...

Page 102

102 Section 9: Subroutines 
 
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  to  stack  of  subroutines  seven 
levels  deep  (this  does  not  count  the  main  program  level).  The  operation  of 
nested subroutines is as shown below: 
Main Program 
bA  b1  b2  b3  b4 
         
         
G1    G3     
  G2    G4...

Page 103

 Section 9: Subroutines 103 
 
MAIN PROGRAM 
|¥   
´ CLEAR M (Not programmable.) 
000-  
001- ´ b 9 Start main program. 
002- | R    Radians mode. 
003- O 0 Stores x2 in R0. 
004- ®  Brings x1 into X; x2 into Y. 
005- O - 0 (x2 - x1) in R0. 
006- G .3 Transfer to subroutine ―.3‖ with x1. 
   Return from subroutine ―.3‖. 
  007- “  - y1. 
008- ® Brings x2 into X-register. 
009- G .3 Transfer to subroutine with x2. 
   Return from subroutine ―.3‖. 
  010- +  y2 - y1. 
011- l ÷ 0 Recalls (x2 – x1) from R0...

Page 104

104 Section 9: Subroutines 
 
Example:  Nesting. The  following  subroutine,  labeled  ―.4‖,  calculates  the 
value of the expression  as part of a larger calculation in a 
larger  program.  The  subroutine  calls  upon another subroutine (a  nested 
subroutine), labeled ―.5‖, to do the repetitive squaring. 
The program is executed after placing the variables t, z, y, and x into the T-, 
Z-, Y-, and X-registers. 
Keystrokes  
´ b.4 Start of main 
 subroutine. 
| x  x2. 
G.5 Calculates y2 and  
 x2 + y2....

Page 105

 Section 9: Subroutines 105 
 
Further Information 
The Subroutine Return 
The pending return condition means that the n instruction  occurring 
subsequent  to  a G instruction  causes  a  return  to  the  line  following  the 
G rather  than a  return  to  line  000.  This  is  what  makes  a  subroutine 
useful  and  reuseable  in  different  parts  of  a  program:  it  will  always  return 
execution to  where  it  branched  from,  even  as  that  point  changes.  The  only 
difference between using a...

Page 106

 
106 
Section 10 
The Index Register  
and Loop Control 
The  Index  register  (RI)  is  a  powerful  tool  in  advanced  programming  of  the 
HP-15C. In addition to storage  and recall of data  the  Index  register can use 
an index number to: 
 Count and control loops. 
 Indirectly  address  storage  registers,  including  those  beyond R.9 
(R19). 
 Indirectly branch to program line numbers, as well as to labels. 
 Indirectly control the display format. 
 Indirectly control flag operations....

Page 107

 Section 10: The Index Register and Loop Control 107 
 
Indirect Program Control With the Index Register 
The V key  is  used  for  all  forms  of  indirect  program  control other  than 
indirect  register  addressing.  Hence, V (not %)  is  used  for  indirect 
program  branching,  indirect  display  format  control,  and  indirect  flag 
control. 
Program Loop Control 
Program loop counting and control can be carried out in the HP-15C by any 
storage register: R0 through R9, R.0 through R.9, or the...

Page 108

108 Section 10: The Index Register and Loop Control 
 
Indirect Addressing 
If RI contains: % will address: t V or GV will transfer to:* 
21 R21 ´ b B 
22 R22              C 
23 R23              Á 
24 R24              E 
⋮ ⋮ — 
65 R65 — 
*For RI  0 only. 
Index Register Arithmetic 
Direct. O or l { + , -, *, ÷ } V.  Storage  or  recall 
arithmetic  operates  with  the  Index  register  in  the  same  manner  as  upon 
other data storage registers (page 43). 
Indirect. O or l { + , -, *, ÷ } % carries...

Page 109

 Section 10: The Index Register and Loop Control 109 
 
To  Labels. If  the  RI value  is positive, t V and G V will 
transfer execution to the label which corresponds to the number in the Index 
register (see the above table). 
For  instance,  if  the  Index  register  contains  20.00500,  then  a tV 
instruction  will  transfer  program  execution  to ´b A.  See  the  chart 
on page 107. 
To  Line  numbers. If  the  RI value  is negative, tV causes  branching 
to  that line  number (using  the...

Page 110

110 Section 10: The Index Register and Loop Control 
 
For example, the number 0.05002 in a storage register represents: 
nnnnn x x x y y 
    0.0 5 0 0 2 
Start count at zero. Count by twos. 
Count up to 50. 
I and e Operation. Each  time  a  program  encounters I or 
e it  increments  or  decrements nnnnn (the  integer  portion  of  the  loop 
control  number),  thereby  keeping  count  of  the  loop  iterations.  It  compares 
nnnnn to xxx, the  prescribed  test  value,  and  exits the  loop  by...
Start reading HP 15c Manual

Related Manuals for HP 15c Manual

All HP manuals