bytemove question
RS_Jim
Posts: 1,764
in Propeller 2
Will it work to shift a line of bytes to the right by one byte using bytemove like this? bytemove(array[2],array[1],5) I want to put 4 bytes into the var called array one at a time shifting the bytes to the right before adding the new one at the left begining of the line. The last byte is a"don't care just a space to let the bytes to fall into with the bytemove.
Thanks
Jim
Comments
Do this:
bytemove(@array[1], @array[0], 4)
Make sure array has a dimension of 5. (As you had written it, it would need to be 7 bytes long, but it wouldn't have worked anyway, since you left out the @'s.) The Spin interpreter will do the move properly for you automatically, without overwriting data that you don't want overwritten.
-Phil
I did this little experiment. Is this what you're looking for?
BTW... if your array is always going to be four bytes, you can just use a long.
Right you are, Jon! Dimension 4, and move 3.
-Phil
Thanks Jon and Phil,
The use of the @ symbol gets me every time. I think I like best Jon's idea of just using an array of longs as it does not waiste that extra byte in every cell of the array and neatly leaves every thing aligned on long boundries
Thanks
Jim
The Spin2 "move" commands figure out whether they should move first-to-last or last-to-first, based on the source-destination relationship.
The Spin1 move commands do that, too, so a moved datum doesn't propagate through the whole array.
-Phil
You don't need an array of them. Just one will suffice. But you'll have to reframe your move command, thus:
bytemove(@longvariable + 1, @longvariable, 3)
-Phil
You don't need to use bytemove. If you're adding to the LSB end, do this:
If you're adding to the MSB end, do this:
Or maybe:
Faster, slower, bigger, smaller?
-Phil
OK, I like the idea of using a long to store the 4 bytes. What I am trying to do is take 4 ADC readings sum them together and devide by 4. to get an average.
Jim