<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>
Date   : Fri, 16 Dec 2011 13:44:09 +0100
From   : kortink@... (John Kortink)
Subject: 32016 + 32082

On Fri, 16 Dec 2011 11:25:08 +0000 (WET), Peter Coghlan
<BBCMICRO@...> wrote:

>[...]
>
>BBC BASIC uses the 6502 stack like any 6502 program but to avoid overflowing
>it when processing (for example) recursive procedure or function calls, BASIC
>saves the contents of the 6502 stack on its own larger stack and reinitialises
>the 6502 stack pointer each time it processes a procedure or function,
>restoring it on return.

The interesting thing, though, is that it doesn't do this to
avoid ordinary stack overflow due to deeply nested PROC/FN
calls, but primarily for performance reasons. Theoretically,
the BASIC stack would be a perfect replacement for the 6502
stack, if it was used exclusively and consistently.

But in the PROC/FN call overhead, where formal and actual
parameters are bound and implicit LOCALs (i.e. formal
parameters with pre-existing names) are saved, processing
would be pretty slow if all the pushes and pops were done
via the BASIC stack. And only because, even in that process,
nesting can occur (since an actual parameter expression can
contain FNs, which can contain yet other FNs, etc.), it needs
to account for that, by pushing and popping the entire 6502
stack (which is far quicker in the end).


John Kortink

-- 

Email    : kortink@...         
Homepage : http://www.inter.nl.net/users/J.Kortink
<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>