![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
David21 Guest
|
Shifting a byte in an Array |
Posted: Wed Jun 07, 2006 2:25 pm |
|
|
I have an array, string[10] and string[10]=0xF.
Is there an operator that will shift the 0xF byte @ index 10 to index 9? I tried to shift_left and<< but they didn't work. Maybe i'm not using it right.
Thanks a bunch! |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Wed Jun 07, 2006 2:43 pm |
|
|
If you just want to move the contents of array[10] to array[9], then simply:
array[9]=array[10];
However assuming you want to move the whole array (the << operator, shifts the _bits_ inside a variable, not the variable itself):
memmove(&array[0],&array[1],10);
Shift_left, can do it, but is more inefficient (you would need to repeat it eight times, for the whole array...), a total of eighty moves...
As I have posted to another thread, it is also worth considering not actually moving the data, but just you access it. ex_sisr, does this for the array holding the incoming data, just moving an address through the array, and 'wrapping' it at the end, so the data itself does not have to move.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
david21 Guest
|
|
Posted: Wed Jun 07, 2006 2:48 pm |
|
|
what i'm trying to do is a FIFO type of buffer. I need every byte to shift down once. Thanks for the help!
![Idea](images/smiles/icon_idea.gif) |
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
|
Posted: Wed Jun 07, 2006 3:00 pm |
|
|
so
memmove(&array[0],&array[1],10);
would move every elements from 2 to 10 to index 1? |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Wed Jun 07, 2006 3:04 pm |
|
|
The memmove, will move element1, to element0, element2 to element1..... element10 to element9.
There are a total of eleven 'elements', but only 10 moves needed.
However for a FIFO buffer, look at the code in ex_sisr. Moving all the data, every time a byte is added/removed, is _very_ labour intensive. This is what circular buffers ar for (implemented in ex_sisr).
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
GEUST Guest
|
|
Posted: Wed Jun 07, 2006 3:06 pm |
|
|
THANKS. ![Cool](images/smiles/icon_cool.gif) |
|
![](templates/subSilver/images/spacer.gif) |
rberek
Joined: 10 Jan 2005 Posts: 207 Location: Ottawa, Canada
|
|
Posted: Wed Jun 07, 2006 3:22 pm |
|
|
I second Ttelmah's observation regarding using moveable pointers rather than moveable data.
When we design FIFOs in ASICs and FPGAs, the data never moves unless it is a trivially small FIFO that can be implemented in flipflops. Most FIFOs are implemented in memory structures, and there is no simple mechanism for shifting all the data, let alone in a small number of clock cycles, as is often required. Thus the simple solution of shifting read and write pointers, and having some logic to make sure they don't pass each other (i.e. an underflow), or that they don't get farther apart than the memory is deep (i.e. an overflow).
Just mentioning this as this is a good habit to get into should you need to write time-critical code. |
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|