On 9/10/2006 at 10:17 PM woodelf wrote:
Well you could use a linked list like LISP.It still
functions
as stack. Local variables still have to be created on entry and
exit how ever from a list of free memory but could be done providing
the computer hardware supports Indirect addressing.
Many systems have neither indirect addressing nor hardware stacks. That's
no bar to stacks being implemented in software.
Linked lists have been used on many implementations (look at the standard
S/360 calling sequence, where each subroutine provides local storage for
the caller's registers). But where recursion comes into the picture,
static saveareas and static locals go out the window.
This can get to be a real problem on older systems where the return address
for whatever the machine implements as a call stores the return address in
the form of an unconditional jump in memory near the entry point of the
called subroutine (yes, I know it's self-modifying code, but this was a
common way to do things). The called routine then has to grab the return
address and store in somewhere that functions as a LIFO stack.
Some machines have more than one stack; one stack stores return addresses;
the other local data.
It can get to be pretty ugly doing recursion in languages that make no
provision for it, such as FORTRAN IV, but it's still possible, using arrays
to store instance-local data and replacing CALLS with ASSIGNed GOTO/GOTO
pairs. Somewhere while programming this kind of spaghetti code, you being
to ask yourself if iteration might not be easier.
Cheers,
Chuck