5 Nested invocation

Most programs have subroutines calling other subroutines. There is nothing mysterious about nested invocations. Just follow the same steps as a single invocation.

Algorithm 3 is an example containing nested invocataions.


\begin{algorithm}
% latex2html id marker 157\begin{algorithmic}[1]
\SUB{abc}...
...d{algorithmic} \caption{A program with multiple invocations.}
\end{algorithm}

The trace of this algorithm is in table 3.


Table 3: A trace of algorithm 3.
line #     comments
8     first line out of a subroutine
9 abc   subroutine ``abc'' stores the line # to return to
  return line #    
  10    
2     the first line in the subroutine to execute
3   def we invoke ``def'' from ``abc''
    return line # this is the return line # that belongs to ``def'', it is independent to the return line # of ``abc''
    4 this is the line immediately following the invocation
6     this is the only line to execute in ``def''
7   return now we return from ``def'' to ``abc'', note which column we use for the return line #, this ``return line #'' column is destroyed after this row in the trace
4 return   we are ready to return from ``abc'', use the stored return line #. Note, again, which column we use to return
10     now we are back to the ``main program''


Copyright © 2006-10-12 by Tak Auyeung