05-15-2008, 04:17 AM
I am looking for a way to declare variable at specific ram position, to be able to read and wright to variable without knowing its name. maybe using word[$1234] if 1234 is the ram position.
Or is there a way in spin to find out a variables ram position?
Thanks in advance.
05-15-2008, 04:46 AM
To find out a variable's position in RAM, you can use the @ operator. It returns the address of the variable in hub RAM. If you want to 'declare' a variable somewhere in RAM at runtime, you can just use a constant with the address, but be very sure to check if the address is occupied or could be occupied. If so, it will cause huge problems!
'to get the address of a variable and assign 1 to it
PUB main | var, addr_var
addr_var := @var
long[addr_var] := 1
long[@var] := 1
'for a locally declared variable (not using the VAR section), it is always a long
'to get the address of a global (in VAR section) variable and assign 1 to it
word var 'can be word, long, or byte. just make sure you address it as so
PUB main | var_addr
var_addr := @var
word[var_addr] := 1
'to just "assign" a variable in ram and assign that position a 1
var_location = $7000
long[var_location] := 1
'you can use byte, word, or long as well
You MUST use either a word or a long to hold the address as it is 16 bit.
I am 1011, so be surprised!
Advertisement sponsored by dfletch:
Come and join us on the Propeller IRC channel for fast and easy help!
Server: irc.freenode.net or freenode.net
If you don't want to bother installing an IRC client, use Mibbit. www.mibbit.com (http://www.mibbit.com)
Post Edited (tpw_man) : 5/14/2008 8:51:24 PM GMT
05-15-2008, 05:14 AM
brilliant, thank you very much.
Also thanks for the quick reply :)