3.1 Basic subroutine control flow

Let us consider the following sample program.


Listing 1: A simple subroutine example
1define sub useless 
2  xy 
3end define sub 
4 
5y
6invoke useless

This program would produce the following trace:







A BCD

Explanation







1line#x y







2pre ? ?

We do not need to assume any value.







3
5
3

We start execution here because this is the first line outside of the definition of a subrotuine. Initialize y.







4
6
retline#

The invocation first allocates a new column, in this case, column D.







5 post

When the subroutine is finished, we continue execution at “post”, which means the execution of the entire program is done.







6
2
3

Start with the first action line of the subroutine being invoked.







7
3
retline#

First, copy the line number of the right-most “retline#” column to the “line#” column of the next row so you remember where to continue execution. Then deallocate the “retline#” column.







8post

Continue execution where the “retline#” column (now deallocated) told us to.