Christofer A
05-15-2008, 03:17 AM
Hi all,
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?
Any suggestions?
Thanks in advance.
Christofer
tpw_man
05-15-2008, 03: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!
Examples:
'to get the address of a variable and assign 1 to it
PUB main | var, addr_var
addr_var := @var
long[addr_var] := 1
'or
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
VAR
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
CON
var_location = $7000
PUB main
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!
Channel: #propeller
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)
http://forums.parallax.com/images/smilies/tongue.gif
Post Edited (tpw_man) : 5/14/2008 8:51:24 PM GMT
Christofer A
05-15-2008, 04:14 AM
brilliant, thank you very much.
Also thanks for the quick reply :)
//Christofer