A little PASM help, please!
markaeric
Posts: 282
Alas, my first foray into PASM. My only previous encounter with ASM was a little bit on the SX, and that's pretty much all forgotten (except for having to move vars to the working register).
Anyways, I know this is real simple, so don't laugh at me too hard!
What I'm trying to do is write data to an array in cog ram. How do I go about addressing each long? Do I simply add some sort of label at the beginning of the array, and then do something like:
add LabelName, 1
mov LabelName, Data
or do I have to create another variable which I use to point to the array? If so, how do I go about doing that? I've been searching for the answer, but didn't come across it. If I did, then I certainly didn't recognize it. I did see an example in Phil Pilgrim's tricks and traps, but there seemed to be some additional complexities that I was confused about.
Thanks,
Mark
Anyways, I know this is real simple, so don't laugh at me too hard!
What I'm trying to do is write data to an array in cog ram. How do I go about addressing each long? Do I simply add some sort of label at the beginning of the array, and then do something like:
add LabelName, 1
mov LabelName, Data
or do I have to create another variable which I use to point to the array? If so, how do I go about doing that? I've been searching for the answer, but didn't come across it. If I did, then I certainly didn't recognize it. I did see an example in Phil Pilgrim's tricks and traps, but there seemed to be some additional complexities that I was confused about.
Thanks,
Mark
Comments
VAR array(value of length of array)
Now Spin can access this array if needed. When you do 'cognew' use the array label as 2nd expression. Then in PASM, PAR provides you access to this array. You need RDLONG or WRLONG to read from/write to the array. Increment pointer to PAR by 4 for each location. Note, WRLONG uses 'value' in the destination and pointer in the source; a bit bass-ackward.
At least this is the way I understand and have used arrays. I've used a 300+ array for an A/D, with the first two locations reserved to pass variables between Spin and PASM.
Don't fall into the trap of accidently assigning less locations to the array than PASM uses. That cog trampled over the variables following 'array' making for a mess to debug
mov ArrayPtr, #Array 'setup the pointer to the first array data address
.....
loop xxx xxxx, ArrayPtr 'do something with the array long
add ArrayPtr, #1 'point to next array long
jmp #loop
ArrayPtr long 0
Array long 0
long 0
long 0
Makes perfect sense! Thanks!
It does? Cog array access without indirection?
I'm messing a bit with movd now. Not sure if it even works yet. Is there a different way?
Edit: Doh! Now I found this thread: http://forums.parallax.com/showthread.php?t=118875
If the array is in COG RAM then you use self modifying code: