I am trying to under stand how to build a barrel shifter using multiplexers. I understand how the barrel shifter works but I don't get how you decide the number of multiplexers to use, and how the shifting is done with the multiplexer basically.
So far wikipedia doen't help much. And the best I have so far is https://tams-www.informatik.uni-hamburg.de/applets/hades/webdemos/10-gates/60-barrel/shifter8.html
But it does not really answer my question.
Answer
The number of multiplexer stages equals the binary logarithm of the number of bits to be shifted.
Each stage passes the value either unchanged or shifts it by 2^n where n is the number of the stage starting with 0. The first stage shifts by one (2^0) bit, the second by two (2^1), the third by four (2^2) and so on.
If all stages are in shift mode then a total shift of 2^n + 2^(n-1) + ... 1 = 2^(n+1) - 1 is obtained. For three stages that would be 2^3 - 1 = 7 bits, what is exactly the required maximum, since a shift of 8 bits would equal to no shift at all.
Assuming the data width is 8 bits, 3 stages are required because 2^3 = 8.
The total number of multiplexers is given by the number of multiplexers per stage times the number of stages. In this case 8*3 = 24 multiplexers (with two inputs and one output).
No comments:
Post a Comment