Array stuff
doft
Posts: 4
Hello and thanks for reading this.
Sorry to post like this, I haven't been able to figure it out or find relevant postings. I'm open to either!
I have a simple program where I define what I believe is an array of longs eg (local_var res 90) and want to access the other elements of this array in asm. A cog will then fill the longs locally.
mov local_var, value
mov local_var<-Next long, next value. How to do this?
.....
I've been racking my brain figuring out how to do this and come up empty. The second part of this to send it to the hub. Under the var heading, I have defined (byte hub_var[360]))That 90 longs=360bytes is no accident.
I've been able to use wrlong to send one long and read out the bytes but thats it. How to do this like an array is my goal.
Again, thanks.
Doft
Sorry to post like this, I haven't been able to figure it out or find relevant postings. I'm open to either!
I have a simple program where I define what I believe is an array of longs eg (local_var res 90) and want to access the other elements of this array in asm. A cog will then fill the longs locally.
mov local_var, value
mov local_var<-Next long, next value. How to do this?
.....
I've been racking my brain figuring out how to do this and come up empty. The second part of this to send it to the hub. Under the var heading, I have defined (byte hub_var[360]))That 90 longs=360bytes is no accident.
I've been able to use wrlong to send one long and read out the bytes but thats it. How to do this like an array is my goal.
Again, thanks.
Doft
Comments
<code>
write mov tmp1, basepntr
add tmp1, idx
movd wrval, tmp1
nop
wrval mov 0-0, value
write_ret ret
'
PWM_NCO long %00100 << 26 ' for counters
basepntr res 1 ' for tables r/w
idx res 1
value res 1
tmp1 res 1 ' work vars
tmp2 res 1
fit 496
</code>
In write, the first thing that is done is copying the value of basepntr into tmp1. Then, adding to tmp1, what is in idx. Wouldn't you have want to set basepntr to the address of the array of variable you want to write to or is this assumed to already have happened? The definition of movd is to set the destination address of the variable in the first field to the value in the second. Is this how you are changing or re-defining the address of this variable?
My next question is what mov 0-0, value is doing. I assume this means writing to wrval, but the syntax is a bit confusing. Can you do mov wrval,value instead?
Thanks
Doft
idx is simply your value used to step through memory. Typically, this is 1 for a byte, 2 for a word, 4 to do a long at a time.
0-0 stands for self-modifying code. movd writes the value of tmp1 to the instruction at label "wrval", so it's literally changed each time through the loop. We use 0-0 by convention, because it doesn't have any other impact on the program, and it sticks out because it doesn't make any other sense.
That's exactly why we use it:)
I agree with Mike. This self modifying code is quite weird so putting a weird thing like "0-0" there to highlight the point is a good idea. Comments are sloppy and often neglected.
As you see when novice sees "0-0" they immediately know something odd is afoot and come here asking what it is. This is a good thing although perhaps it should be described and used in the PASM documentation to save them having to ask.
I really like a quick mention of it in the manual. Seconded.
Have it titled "Self Modifying Code", and then have a brief description of why it happens, how the mechanics work, and a few examples, one with source modified, destination modified, both, and a final one with "#" literal addressing, as opposed to the usual indirect.
That would cover the various forms possible, and a few nice use cases too.
I'm adding that to the tutorial document I've got slowly building. Necessary, IMHO.
-Phil
Closing the thread just happens when nobody writes on it anymore. Or, in a extreme case, one of our moderators may lock it. If you want, you could ask.
In Spin, you might do something like this:
where 'brightness' is the array and 'idx' is the element you want to write. In my PASM code you would specify the address of your array and the element you want to write -- like this:
As you can see, you need to set value, basepntr, and idx before calling write (only basepntr and idx for read).
Hopefully, this clarifies that subroutine.