If you plan to have only one program in the calculator memory, you can separate the routine in various labels. If you plan to have more than one program in the calculator memory, it is better to have routines part of the main program label, starting at a specific line number.

A subroutine can itself call other subroutines.

The flow diagrams in this chapter use this notation:

   1

Program execution branches from this line to the

 

line number marked 1 ("from 1").

   1

Program execution branches from a line number

 

marked 1 ("to 1") to this line.

The example below show you to call a subroutine to change the sign of the number you input. Subroutine E that is called from routine D by line    changes sign of the number. Subroutine E ends with a RTN instruction that sends program execution back to routine D (to store and display the result) at line D004. See the flow diagrams below.

  

 

Starts here.

  

 

 

  

1

Calls subroutine E.

  

2

Returns here.

  

 

 

 

 

 

  

1

Starts subroutine.

 

 

Change sign of the number

 

2

Returns to routine D.

 

 

 

Nested Subroutines

A subroutine can call another subroutine, and that subroutine can call yet another subroutine. This "nesting" of subroutines — the calling of a subroutine within another subroutine — is limited to a stack of subroutines 20 levels deep (not counting the topmost program level). The operation of nested subroutines is as shown below:

14-2Programming Techniques

Page 212
Image 212
HP 35s Scientific manual Nested Subroutines, 14-2Programming Techniques