Understanding Barrel Shifting in VHDL: A 16-bit Implementation

  • Thread starter EvLer
  • Start date
In summary, a barrel shifter is a combinational logic device that incrementally shifts in stages. It has 4 stages, each of which can choose to shift or not to shift, giving any total shift amount. This allows for flexible shifting, such as shifting an input by 9 bits by enabling stages 1 and 4. The device is made up of muxes and wires, and can enable any combination of the 4 shifters to achieve a total shift of up to 15 bits.
  • #1
EvLer
458
0

Homework Statement


A, and B both are 16 bits wide; A is entity to shift and B is by how much;
we are supposed to implement a BARREL shifter. And here's the explanation (which does not make much sense to me, esp. the example) given in lab document:

A barrel shifter is a combinational logic device that incrementally shifts in stages. In our barrel shifter, we will have 4 stages. Each stage can choose to shift or not to shift, giving any total shift amount. For example, to shift an input by 9, stages one and four will shift 1 time and 8 times, respectively. Stages two and three will not shift. Notice that the binary number 9 is "1001". How convenient that the fourth bit and the first bit are 1 and the second and the third bits are 0.

The Attempt at a Solution


ok, I know how to write the shift register, a regular without the "barrel", and after some googling, I found that barrel basically shifts by the amounts of bits specified at once. If someone could explain how the description from the lab document makes sense that is all i need to understand... thanks in advance.
 
Physics news on Phys.org
  • #2
I presume you have four shifters wired up in series, the output of one connected to the input of the next. Each shifter is also followed by a mux, so that you can bypass each shifter if you do not wish to use it.

The first shifter shifts only one bit position. If the value put into the first shifter is 10010010, you'll get out 00100100.

The second shifter shifts two bit positions. If you put in 10010010, you'll get out 01001000.

The third shifter shifts four bit positions, and the fourth shifter shifts eight bit positions.

By "enabling" some combination of these individual shifters (i.e. by not bypassing them with a mux), any total shift from zero bits to fifteen bits is possible. Note that this device is really nothing more than muxes and wires.

- Warren
 
Last edited:
  • #3
ok, that makes a bit more sense...
so, just to make sure, let's say he wants us to shift left by 10, which is "1010" then shifter 2 and 4 are enabled, so I will shift by 2 first and then by 8, right?
So if the input is "1010 0111 0001"
then I will have after shifter 2: "1001 1100 0100"
then after shifter 4: "0100 0000 0000 0000"

edit: one more thing: it seems like I will be able to shift only 15 times is that how it's supposed to work out?:uhh:

thanks sooo much...
 
Last edited:
  • #4
that looks correct to me :smile:
 

What is a barrel shifter 16-bits in VHDL?

A barrel shifter is a digital circuit that can shift the bits of a binary number by a specified number of positions. In VHDL, it is a module that can be used to perform barrel shifting operations on 16-bit binary numbers.

How does a barrel shifter 16-bits work?

A barrel shifter typically consists of a series of multiplexers and registers. The input number is fed into the first multiplexer, which selects the output based on the specified shift amount. The shifted output is then fed into the next multiplexer and the process is repeated until the desired shift amount is achieved.

What are the advantages of using a barrel shifter 16-bits?

Barrel shifters offer efficient and fast shifting of binary numbers compared to other methods such as using a shift register. They also have a fixed execution time, regardless of the shift amount, making them suitable for applications where speed and efficiency are important.

Can a barrel shifter 16-bits perform both left and right shifts?

Yes, a barrel shifter in VHDL can perform both left and right shifts. The direction of the shift is determined by the control signals provided to the multiplexers.

How can I implement a barrel shifter 16-bits in my VHDL code?

You can implement a barrel shifter by defining a module with input and output ports for the binary number, shift amount, and control signals. The internal logic for the shifting can be implemented using multiplexers and registers. You can also use a pre-existing library of VHDL code for barrel shifters.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
10
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
10
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
8
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
13K
  • Engineering and Comp Sci Homework Help
Replies
9
Views
36K
  • Programming and Computer Science
Replies
1
Views
1K
Replies
9
Views
1K
  • Programming and Computer Science
Replies
5
Views
3K
Back
Top