Section 13: Indirect Operations204
   
  Execution
   
        TSOLVE  
        ASTO 15  
   
       
GTO IND 15  
       
 
         
   
   
LBLTSOLVE  
           
To indirectly address routines or programs outside the current program, you can use XEQ g nn (execute indirect). When the running program encounters an XEQ IND nn instruction, execution is transferred to the numeric or ALPHA label specified by the indirect address register. The addressed program is executed as a subroutine and control returns to the main program when execution of the subroutine is completed. For example, with the label CIRCLE stored in R16, XEQ g 16 causes execution of the program defined by LBL CIRCLE. Local labels (A through J, a through e) cannot be used indirectly with XEQ .
Note that only programs that you write and store into program memory and those functions contained in plug-in extensions (such as application module, or the card reader) can be executed indirectly in this manner. Standard HP-41C functions cannot be executed with XEQ g .
  Execution        
  TCIRCLE LBLTCIRCLE  
  ASTO 16
 
    XEQ IND 16  
 
END  
 
       
Indirect addressing works the same way with all of the functions listed on page 000.
Problems
  1. One method of generating pseudorandom numbers in a program is to take a number (called a ‘‘seed’’), square it, and then remove the center of the resulting square and square that, etc. Thus, a seed of 5,182 when squared yields 26,853,124. A random number generator could then extract the four center digits, 8,531, and square that value. Continuing for several iterations through a loop would generate several random numbers. Following is a flowchart and programming hints for such a pseudorandom number generator.
    The seed is a four-digit number in the form of nn.nn, .nnnn, or nnnn. The seed is squared and the square truncated by the main part of the program, and the resulting four-digit random number is displayed in the form of the original seed.