Array question
blittled
Posts: 681
I am using an array as a FIFO stack. If I use the following
to move 13 bytes "up" the stack will the move work or will the array be destroyed?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Will work for Propeller parts!
bytemove (@buffer, @buffer+13, 247)
to move 13 bytes "up" the stack will the move work or will the array be destroyed?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Will work for Propeller parts!
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon McPhalen
Hollywood, CA
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Will work for Propeller parts!
@testbuf, @testbuf+5, 5
of course works, as the number of bytes matches with the offset.
@buffer, @buffer+13, 247
won't work (my guess), as it shall move more than 13 (the offset) bytes. The first 13 bytes are fine, but with the 14th byte the move reaches the region where it previously already copied the first 13 bytes to. In the end the stack will always repeat the same 13 bytes again and again.
Alternatives:
1. If you want to use bytemove you need to move it from the end to the top in 13 byte bunches. Which means you have to call bytemove several times (247 / 13).
First call would be bytemove( @buffer + 247 - 13, @buffer + 260 - 13, 13 ), second call bytemove( @buffer + 247 - 2*13, @buffer + 260 - 2*13, 13 ) ... and so on ... of course you can do that in a loop.
2. You could run a modified SPIN interpreter which implements the bytemove differently. Instead of copying from lower address to higher address you can do it the other way around.
3. Propably the easiest if you can efford the extra HUB-RAM: first copy from @buffer to a totally different buffer and from there copy it to @buffer+13
Post Edited (MagIO2) : 6/29/2010 7:43:05 AM GMT
But that's beside the point. The bigger issue is that shuttling bytes like this is not the most efficient way to implement a queue (a.k.a. FIFO buffer). It's better just to leave the queue contents alone and manipulate a pair of pointers that indicate the current head and tail of the queue, and which cycle back to the beginning when they overflow the end.
-Phil