Word array into a long array
Dave Matthews
Posts: 93
I would like to take a word size array and feed it into a long size array.
I would like the wordtest[0] element to become the longtest[0] element ... wordtest[1] to become longtest[1],... and so on.
Dave
I would like the wordtest[0] element to become the longtest[0] element ... wordtest[1] to become longtest[1],... and so on.
Dave

Comments
pub move(p_la, p_wa, count) '' Move values in word array to low words of long array '' -- p_la is pointer to long array (dest) '' -- p_wa is pointer to word array (src) '' -- count is number of elements to move (i.e., copy) repeat count [B]word[/B][p_la] := word[p_wa] ' copy element p_la += 4 ' update long pointer p_wa += 2 ' update word pointerThis assumes that you do not want the upper word of the long array to be modified by the copy. If you don't want to keep the original high word contents in the long array, you can do this with a simple loop, or modify the above code like this
pub move(p_la, p_wa, count) repeat count [B]long[/B][p_la] := word[p_wa] ' copy element p_la += 4 ' update long pointer p_wa += 2 ' update word pointerThe reason for pointers is that the method will work with any arrays you have.
I do want the upper words to be zeroed so the simple loop is for me (didn't see the other loop?).
I am grateful that you did not have to refer me to a spin language command that would do the same thing, I always try to check everything and OBEX before posting a question here.
At any rate your description is very clear and I am very grateful.
Dave
repeat idx from 0 to len-1 longarray[idx] := wordarray[idx]Boom! Done. Now, this is fine if you only have to two arrays. If there are more then you can use the second snippet above and pass pointers.
... for example, if you had 10 elements to move. BTW... names are resolved to pointers internally, so getting comfortable with them is a useful way to create more flexible code.
pub move(p_la, p_wa, count) : n repeat count long[p_la][n++] := word[p_wa][n]This uses a local variable as an index. I know it seems odd to have the post-increment on the left side but this is where it belongs; we don't want to increment N until the value has been moved from one array to another. Note, too, that he's actually using the result variable (this is noted by the use of : after the method name); this variable is always set to zero on entering a method.
Dave