best way to access variable of an object
I don't know weather to use a get method or pass addresses to access variables modified by some assembly code, so far I can't get the address passing via the start method to work. below is an example of what I mean:
I thought the call to this start method which passed pointers to its own data variables would then be able to access the latest values without a get(index) method, but it doesn't work for some reason.
VAR long data(5] PUB start(dataAddr0,dataAddr1,dataAddr2,dataAddr3,dataAddr4) longmove(@data[noparse][[/noparse]0],@dataAddr0,5) cognew(@entry,@data[noparse][[/noparse]0]) DAT org 0 entry 'assembly code here which modifies data[noparse][[/noparse]] elements
I thought the call to this start method which passed pointers to its own data variables would then be able to access the latest values without a get(index) method, but it doesn't work for some reason.

Comments
And, these a very easy way arround this.
Since asm code just floats arround in the main memory it can be acessed like any other code.
So, you can assign and asm long variable the address of a variable for spin and then launch the processor with all the addresses embeded in it.
Like:
var
stuff [noparse][[/noparse]6]
Pub
adrStuff := @stuff
cognew...
Dat
...
adrStuff long 0
......
Doing it this way is quick and painless.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
' call with myObject.start(@myArray) PUB start(addressOfLongs) cognew(@entry,addressOfLongs) DAT entry rdlong temp1,par ' 1st parameter mov tempAddr,par add tempAddr,#4 ' 2nd parameter rdlong temp1,tempAddrIf you want to pass several parameter addresses, you could do
PUB start(dataAddr0, dataAddr1) pointer0 := dataAddr0 ' Set pointers in hub memory pointer1 := dataAddr1 cognew(@entry,0) ' Copy code and initialized pointers to cog & start DAT entry rdlong temp1,pointer0 rdlong temp2,pointer1 pointer0 long 0 ' Set by start routine before pointer1 long 0 ' code is copied to the cogfirst object, declared by 2nd object:
'object1.spin VAR long data{5] PUB start(dataAddr0,dataAddr1,dataAddr2,dataAddr3,dataAddr4) longmove(@data[noparse][[/noparse]0],@dataAddr0,5) cognew(@entry,@data[noparse][[/noparse]0]) DAT org 0 entry 'asm code which modifies data[noparse][[/noparse]]2nd object, declares first object
'object2.spin OBJ object : "object1" debug : "FullDuplexSerial" VAR long data{5] PUB go | index object.start(@data[noparse][[/noparse]0],@data{1],@data{2],@data{3],@data{4]) debug.start(31,30,0,9600) repeat debug.tx(16) repeat index from 0 to 4 debug.str(string("data ")) debug.dec(index) debug.str(string(": ") debug.dec(data[noparse][[/noparse]index]) debug.tx(13) waitcnt(cnt + clkfreq/10)now in theory, the 2nd object should print out whatever the first object stores in its data variables, but it doesnt. I have verified that it is able to store the variables in main memory and the asm code works by putting the loop to print them out in object1 and removing the parameters to the start() method and loading the code directly. I do not want to use a get(index) method to return the data each time because it needs to be semi-fast.
Post Edited (Scott Lewis) : 2/19/2009 1:08:01 AM GMT
obj object : "object1" debug : "FullDuplexSerial" var long data[noparse][[/noparse] 5 ] PUB go | index object.start(@data) debug.start(31,30,0,9600) repeat repeat index from 0 to 4 debug.dec(data[noparse][[/noparse]index]) debug.tx(13)