<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>
Date   : Mon, 31 Jan 2005 22:42:23 +0000
From   : jgh@... (Jonathan Graham Harston)
Subject: Re: ON...

Dave Gorst <dgorst@...> wrote:
> I've got to ask - what was different with the implementation of
> procedures in BASIC V? I remember GOSUBs being regarded as faster in
> the earlier versions of BASIC but did something change when the Master
> (I think that was version 5) came along?
 
All 6502 BBC BASICs use the same method of implementing GOSUB:
 
Push BASIC program statement pointer on GOSUB stack.
Scan through from PAGE to TOP looking for destination line.
If not found, give error "No such line".
Load program statement pointer with start of line
Return to statement execution loop.
 
All 6502 BBC BASICs use the same method of implementing PROC/FN:
 
Push BASIC program statement pointer on BASIC stack.
Scan though variable heap for FN/PROC entry.
If not found THEN
  Scan through from PAGE to TOP looking for a line starting
  with DEF<name>
  If not found, give error "No such FN/PROC"
  Create a heap entry for the FN/PROC with it's program address
ENDIF
Load program statement pointer with FN/PROC program address
 
ARM BASIC manages entries in the heap slightly differently. This isn't
gospel[1], but it's something like this:
 
When a PROC or FN is called (maybe also for variables), a search is made
of a table of addresses of the location *in the program* of that call, to
see if it has been called already. Is much faster to do compares of
fixed-sized words, than it is for arbitarily-long strings.
 
This means that program that self-modify the calling name of a procedure
will not work as expected:
 
FORa=1TO3:PROCa:NEXT:END
DEFPROCa:PRINT"A";:?(PAGE+12)=ASC"b":ENDPROC
DEFPROCb:PRINT"B";:ENDPROC
 
This will print AAA, not ABB as expected, as on the second and later
passes of the loop, BASIC V searches the FN/PROC table for the address of
the PROC in the first line, ignoing it's actual name.
 
Sophie gave a good explanation of this on one of the acorn groups about a
year or so ago.
______________
[1] Gospel: Allegories and stories used to illustrate a point.
 
-- 
J.G.Harston - jgh@...                - mdfs.net/User/JGH
Badly formed email is deleted unseen as spam
<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>