AddrOf - Find Address of a Variable =================================== File: AddrOf - Update: 1.00 Author: J.G.Harston - Date: 02-Dec-2009 BBC BASIC for Windows implements the ^identifier function (as opposed to the num ^ num operation) to return the address of a variable. For example, ^fred% returns the address where the data for the variable fred% is stored. This can be implemented on other versions of BBC BASIC with the AddrOf library. Requirements and Dependancies ============================= None. The appropriate AddrOf library routine must be used for the platform running on. Routines are available for 6502, Z80, PDP-11, DOS and ARM, called with FNAddrOf_65, FNAddrOf_Z80, FNAddrOf_PDP, FNAddrOf_DOS and FNAddrOf_ARM. Usage ===== Once FNAddrOf is called to set up the machine code with, for example: addrof%=FNAddrOf_65 then the address of a variable can be found with CALL addrof%,result%,variable leaving the address in result%. result% must be a pre-existing integer variable, and CALL addrof% must have at least two parameters or undefined problems will occur. BBC BASIC for Windows allows ^PROCname and ^FNname. This code only supports those variables that can be passed to the CALL command. After calling, result% holds the address of the variable's data block, as with parameters passed to CALL. This will be the following: CALL addrof%,result%,num result% -> 5-byte floating point value CALL addrof%,result%,num% result% -> 4-byte integer value CALL addrof%,result%,str$ result% -> string information block The string information block is different on different platforms. 6502: result%+0 2-byte string address +2 1-byte allocated string length +3 1-byte actual string length Z80: result%+0 2-byte string address +2 1-byte allocated string length +3 1-byte actual string length DOS: result%+0 allocated string length +1 1-byte actual string length +2 2-byte string address PDP-11: result%+0 2-byte string address +2 1-byte allocated string length +3 1-byte actual string length ARM: result%+0 4-byte string address +4 1-byte actual string length Windows: result%+0 4-byte string address +4 2-byte allocated length +6 2-byte string length Examples ======== REM Print exponent of PI num=PI CALL addrof%,A%,num PRINT "Exponent: ";?A% REM Load 4-byte file into a variable fred%=0:CALL addrof%,addr%,fred% OSCLI "LOAD data "+STR$~addr% REM Swap byte order big%=&12345678 little%=big% CALL addrof%,A%,little% tmp%=A%?0:A%?0=A%?3:A%?3=tmp% tmp%=A%?1:A%?1=A%?2:A%?2=tmp% Version History =============== 1.00 02-Dec-2009 First version written.