Section 13: Indirect Operations203
Keystrokes Display    
XEQ 
       
   
ALPHA DSE ALPHA 02 
  12 DSE 02    
  Subtract one from the loop control number in R02. Test loop control number: if it is not less than or equal to zero, execute loop again; if it is, skip the next line.
g GTO 02 
  13 GTO 02    
  Loop to LBL 02.
g GTO · · 
  00 REG 42    
   
Run the program now and listen to the audible tone of the HP-41C as it starts with a low pitch, works up to a high pitch, then back down to the low pitch.
Keystrokes Display    
PRGM 
  0.0000    
   
XEQ 
       
   
ALPHA SONG ALPHA 
  9.0000    
   
When you run the program, it executes through the first loop until the loop control number in R01 equals 9. The TONE function uses the loop control number in R01 indirectly as a specification of the TONE value. When the loop control number equals 9, the second loop begins execution until the loop control number equals 0. TONE uses the loop control number in R02 indirectly as the TONE specification. The second loop does not execute TONE 0.
Indirect Control of Branches and Subroutines
Like indirect addressing of storage registers, you can address routines, subroutines, even entire programs using indirect addressing.
To indirectly address a subroutine with an ALPHA or numeric label (e.g., LBL TRIGO, LBL 10), use the GTO g nn (go to indirect) instruction in the program. (The calculator displays the prompt IND following the function name.) When the running program encounters the GTO IND nn instruction, the calculator searches the current program for a numeric label and all of program memory for an ALPHA label that is specified by the indirect address register. (If the label is not found, or if the label is not a legal label—e.g., the numeric label is grater than 99, the display shows NONEXISTENT.) Local labels (A through J, a through e) cannot be used indirectly with GTO .
As an example, with the ALPHA label SOLVE stored in register R15, when the GTO IND 15 instruction is encountered, execution is transferred to the last LBL SOLVE in memory. If the label SOLVE is found. execution resumes there. A GTO to a numeric label will not transfer execution out of a program file, but a GTO to an ALPHA label will transfer execution out of a program file (refer to section 12 for a complete discussion of label searching, branches and transferring execution).