Barrel Shifter
Build a barrel shifter that can shift data by any number of positions in a single clock cycle—a key component in ALUs for fast multiplication and division.
Overview
While a shift register moves data one bit per clock, a barrel shifter can shift by any amount instantly using combinational logic. A 4-bit barrel shifter uses multiplexers to route each input bit to any output position based on a shift amount. This is how CPUs perform fast shifts for multiplication, division, and bit manipulation without waiting multiple clock cycles.
Components Needed
- 4x SN74HC153 IC (Dual 4:1 MUX)
- 4x LED
- 6x Switch
- severalx Wires
Instructions
Design the Shift Network
For a 4-bit barrel shifter, each output needs a 4:1 MUX selecting from the 4 inputs. The shift amount (0-3) controls which input reaches each output position.
Wire the MUX Array
Use four 4:1 MUXes (two 74HC153 ICs). Connect the shared select lines to switches representing the 2-bit shift amount. Wire inputs to MUXes according to the shift pattern.
Connect Data Path
Connect 4 data input switches to the appropriate MUX inputs based on shift amount. Connect MUX outputs to 4 LEDs showing the shifted result.
Test All Shift Amounts
Set a pattern like 1000, then try shift amounts 0, 1, 2, 3. Verify: shift-0 = 1000, shift-1 = 0100, shift-2 = 0010, shift-3 = 0001.
Challenges
- Add left/right shift direction control
- Implement rotate (circular shift) mode
- Extend to 8 bits using more MUX stages
- Build an arithmetic shifter that preserves the sign bit