Section 12: Subroutines188
First
Program
  Six returns can be pending.
Subroutines
 
LBL MAIN   LBL 01   LBL 02   LBL 03   LBL 04   LBL 05   LBL 06
   
XEQ 01 XEQ 03 XEQ 05    
    XEQ 02       XEQ 04       XEQ 06      
         
  RTN RTN RTN RTN RTN RTN END  
The calculator can return back to the first program from subroutines that are six deep, as shown. However, if you call up subroutines that are more than six deep, the calculator will return only six subroutines deep. For example, if you call up seven subroutines deep, when the seventh subroutine is completed, execution will transfer back only six subroutines, back to the second subroutine executed.
Naturally, the calculator can execute an END or RTN instruction as a stop any number of times. Also, if you execute any of the subroutines manually from the keyboard (or you press g RTN ) all pending END and RTN instructions are forgotten by the calculator.
Single-Line Execution of Subroutines
If you are executing a program one step at a time with SST key in normal mode, and encounter an XEQ instruction, the calculator will then transfer execution to the specified subroutine. You can then execute the subroutine one line at a time with SST . When you encounter the END or RTN in the subroutine, execution transfers back just like a running program. You can execute programs this way, with SST , and the HP-41C will remember up to six pending returns, as in a running program.
Local Labels
Earlier in section 7 you learned how to label or name a program with a string of ALPHA characters. There are 15 ALPHA labels on the HP-41C that have special functions that are called ‘‘local labels.’’ These labels are LBL A through LBL J and LBL a through LBL e (shifted A through E). Any time you label a portion of a program or a subroutine with one of these labels, it is a local label.
When the HP-41C is in USER mode and you press one of the keys in the top two rows (or g and a top row key), the calculator immediately begins searching for the corresponding (A through J, a through e) local label within the current program. If the local label is not found, the calculator executes the function printed on the face of, or above, the key.
For example, when you press Σ+ in USER mode, the calculator first searches for a LBL A instruction in the current program. The calculator searches downward from the current position in program memory to the end of the program. Then it begins searching at the beginning of the program and back to where the search began.