passing arrays to assembly and back
swampie777
Posts: 33
How can I pass an array to assembly and back? I want to read several ports, place the values in an array and do something with them once back in spin code.
Thanks,
Swampie777
Thanks,
Swampie777
Comments
if you have a single array you can give its address as the par of the cognew statement
cognew(@work, @array)
in the cog you need to use self modifying code, and the movs, or movd for move source and move destination. an example of this is
cog_array long 0[noparse][[/noparse]10]
you have to have the :loop separated from : next by one instruction because the data from the next instruction is loaded before the current instruction finishes
for retrieving code from the hub you will use movd because the cog is your destination, for manipulating the data in the cog you will use movs because the cog is your source. then for sending back to the hub you will use movd again because hub operations are strange and the hub address is always in the source field.
for more look at page 21 of the pdf attached here http://forums.parallax.com/forums/default.aspx?f=25&m=209237
Post Edited (Alsowolfman) : 8/21/2009 8:24:53 PM GMT
In my current application I'm reading two pins for a high level, recording the clock counts by difference( one at a time) and trying to pass the results back to spin. I have the spin code in a loop to grab 16 values. I get 16 unique first values, and 16 copies of the first second value.
If I run a program to just collect one value from one pin at a time the magnitudes compare correctly with the above code and with the oscilloscope outputs.
you need to define parplus4 before the loop, every cycle you get an additional par added to it, so
loop1 parplus4= par + 4
loop2 parplus4=par+par+4
...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
--Steve
Propeller Tools