Section 12: Subroutines178
As you can see, the only difference between a subroutine and a normal branch is the transfer of execution after the END or RTN . After the GTO , the next END or RTN halts a running program. After an XEQ , the next END or RTN returns execution back to the main program, where it continues until another END or RTN is encountered.
Subroutine Types and Label Searching
Basically, there are two types of subroutines that you can use in your programs. Subroutines are either inside the program file or outside the program file. Each of these types of subroutines must be terminated properly. Here are some details.
  1. Numeric labels and local ALPHA labels (A through J and a through e, more about these later) are used for program and subroutines inside the program file. The calculator searches for these labels inside the current program file only.
    Searches for numeric labels and local ALPHA labels begin at the current position in a program and progress downward through the program to the first END . If the label is not found, searching begins at the beginning of the program file and downward to where the search began. If the label is still not found, the display will show NONEXISTENT.
    Programs and subroutines inside program files are usually terminated with RTN . This is because the main program file that they are part of has its own beginning label and ends with an END . However, if the subroutine is at the end of the program file, the END of the program file will suffice to also end the subroutine.
  2. Programs with ALPHA labels are generally used for program and subroutines outside other programs. The calculator searches all of program memory for ALPHA labels. The ALPHA label search begins with the last ALPHA label in program memory and upward through all of the ALPHA labels in program memory. If the label is not found, the display will show NONEXISTENT.
    Programs and subroutines outside program files are usually terminated with END . This is because they must stand alone as separate programs in program memory.
    Note that several subroutines of subprograms can be grouped together as a single ‘‘program.’’ All but the final routine should be terminated with RTN instructions. The final routine should be terminated with END . In this case, each of these subroutines can be labeled with ALPHA labels.