8-bit Logical Barrel Shifter
A barrel shifter shifts by any amount in a single cycle by passing the data through stages of muxes. With log2(N) stages, each shifting by a power of two, it stays small.
This module performs a logical left shift on an 8-bit input vector. The shift amount is specified by a 3-bit control signal, allowing shifts from 0 to 7 bit positions. Zeros are shifted into the vacated least significant bits.
The entire shifting operation must be executed using exactly three cascading stages of 2-to-1 multiplexers. Stage 0 applies a shift of 1 position. Stage 1 applies a shift of 2 positions. Stage 2 applies a shift of 4 positions. By selectively enabling these stages based on the shift amount bits, any shift between 0 and 7 can be constructed combinationally.
| Signal | Direction | Width | Description |
|---|---|---|---|
data_in |
input | 8 | The 8-bit data vector to be shifted. |
shift_amt |
input | 3 | The 3-bit shift amount controlling the multiplexer stages. |
data_out |
output | 8 | The purely combinational shifted 8-bit result. |
Constraints
- The module must be entirely combinational logic.
- The design must be structurally built using exactly three stages of 2-to-1 multiplexers.
- The use of Verilog shift operators is strictly prohibited.
- Zeros must be shifted into the vacated least significant bits during a logical left shift.
- No clock or reset signals are used.
Topics
Solve this problem
Write the module in Verilog, SystemVerilog or VHDL. Your submission is compiled and simulated against the problem's testbench. You get the waveform back, not a stored answer.
Free to solve. A Codiode account keeps your progress.
The circuit builder and code editor need a desktop screen. On a phone, read the problem here and open it on a laptop to solve.
Part of Datapath Design
Problem 3 of 27 in the Datapath Design track.
Related problems
Browse all problems · Verilog practice problems · Learning tracks