Example: A Nested Subroutine.

The following subroutine, labeled S, calculates the value of the expression

a2 + b2 + c2 + d2

as part of a larger calculation in a larger program. The subroutine calls upon another subroutine (a nested subroutine), labeled Q, to do the repetitive squaring and addition. This saves memory by keeping the program shorter than it would be without the subroutine.

2 €

4 €

6 €

246

 

 "! 

 "! 

 "! 

 "! 

 

 

 

   º  %   %   %   !  !

    º65¸  º  -  !

Starts subroutine here.

Enters A.

Enters B.

Enters C.

Enters D.

Recalls the data.

€ 1

A2.

€ 3

A2 + B2.

€5 A2 + B2 + C2

A2 + B2 + C2 + D2

Returns to main routine.

135 Nested subroutine

Adds x2.

Returns to subroutine S.

13–4 Programming Techniques

File name 32sii-Manual-E-0424

 

Printed Date : 2003/4/24

Size : 17.7 x 25.2 cm