<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>
Date   : Thu, 03 Dec 2009 21:47:47 +0000
From   : jgh@... (Jonathan Graham Harston)
Subject: Address of a variable

Phill Harvey-Smith wrote:
> Ok so is there an easy way to get the address of a variable in memory ?
> Specifically in BBC Basic 86 ?
 
In BASIC-86 definitely. ^ as a function. It returns the address of
the data block for the identifier.
 
address = ^identifier
 
eg, addr%=^A%  fnptr%=^FNjim  
 
!^var% is the same as var%, ie !^var%=1 is the same as var%=1
 
|^var is the same as var, ie |^var=1.5 is the same as var=1.5
 
^var$ points to the string information block which holds:
  stringaddr, allocatedlenght, usedlenght
 
^FNname and ^PROCname points to the call information block
 
^identifier is available on BBC BASIC for Windows version 2.00 and
later, PDP-11 BASIC and ARM BASIC with the BASIC Plus extensions at
mdfs.net/bbcbasic/RISCOS
 
For other platforms a bit of coding is needed, such as this:
 
   10REM > AddrOf - Find address of variable
   20REM Simulates ^varname available on other BBC BASICs
   30:
   40REM Use with CALL addrof%,varname
   50REM A% gets set to address of variable
   60:
   70DEFPROCaddrof:DIM addrof% 15:FOR A%=0 TO 1
   80P%=addrof%:[OPT A%*2:LDA &601:STA &404:LDA &602:STA &405
   90LDA #0:STA &406:STA &407:RTS:]:NEXT:ENDPROC
 
With this you can then do:
 
  fred%=0
  CALL addrof%,fred%:!A%=6
  PRINT fred%
 
and get 6 printed.
 
-- 
J.G.Harston - jgh@...                - mdfs.net/User/JGH
There are three food groups: brown, green and ice cream.
<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>