Section 9.5: Subroutines (Frame 11)                     [prev][home][     ]

There are many other issues, such as whether functions can be nested and whether they can be recursive. Throughout the decades, many different hardware architectures have been tried to implement resursive subprograms elegantly, although one has prevailed, the stack approach.

A region of memory called the stack is set aside to hold parameters and return addresses of functions. As functions are called, new regions are allocated on the top of this stack, and when functions return, these regions, called activation records or frames, are popped off. Two new registers keep track of which region is being used:

SP stack pointer points to the current top of the stack
FP frame pointer points to the current activation record on the top of the stack

Further discussion of these strategies is best left to a programming languages course. Suffice it to note that compilers, again, come to the rescue, hiding so many details of the underlying machine and its rude, crude machine language system from the programmer.