<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>
Date   : Thu, 03 Dec 2009 23:41:00 +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
 
Doing some testing, and while BBC BASIC for DOS v4.82 and BBC BASIC
for Windows v2.00 are both year 2000 vintage, the ^ function never
got into the DOS version. I've uploaded code for 6502, Z80 and DOS
to beebwiki.jonripley.com/Address_of_a_variable
 
6502:
    DEFPROCaddrof:DIM addrof% 23:FOR A%=0 TO 1
    P%=addrof%:[OPT A%*2:LDA &601:STA &404:LDA &602:STA &405
    LDA #0:STA &406:STA &407:RTS:]:NEXT:ENDPROC
 
Z80:
    DEFPROCaddrof:DIM addrof% 23:FOR A%=0 TO 1
    P%=addrof%:[OPT A%*2:PUSH IX:POP HL:INC H:LD L,4
    LD A,(IX+2):LD (HL),A:INC HL:LD A,(IX+3):LD (HL),A:INC HL
    LD (HL),0:INC HL:LD (HL),0:RET:]:NEXT:ENDPROC
 
DOS:
    DEFPROCaddrof:DIM addrof% 15:FOR A%=0 TO 1
    P%=addrof%:[OPT A%*2:mov ax,ds:[bp+2]:mov ds:[4],ax
    mov ax,0:mov ds:[6],ax:retf:]:NEXT:ENDPROC
 
Usage:
Once you've done PROCaddrof, you can then do, for example:
 
    CALL addrof%,fred%
 
to set A% to the address of the variable fred%.
 
-- 
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 >>