Shift by Variable Amount
Arithmetic logic units and data alignment modules frequently require the ability to shift data by an arbitrary, dynamically changing amount in a single clock cycle. This operation requires a barrel shifter, a purely combinational circuit that routes input bits to specific output positions based on a control vector. Without a barrel shifter, shifting by a variable amount would require multiple clock cycles to complete.
The module accepts an 8-bit data input and a 3-bit shift amount. It performs a logical left shift on the data input by the number of positions specified by the shift amount. Zeros are shifted into the least significant bits. Because this is a purely combinational circuit, the result is driven to the 8-bit output immediately without any clock or reset dependency.
| Signal | Direction | Width | Description | |--------|-----------|-------|-------------| | data_in | input | 8 | Data vector to be shifted | | shift_amt | input | 3 | Number of positions to shift left (0 to 7) | | data_out | output | 8 | Shifted result; combinational output |
Constraints
- The design must be purely combinational; do not use clocks, resets, or flip-flops.
- The shift operation must be a logical left shift where zeros populate the vacated least significant bits.
- Bits shifted beyond the most significant bit of the 8-bit output are discarded.
Topics
Solve this problem
Write the module in Verilog, SystemVerilog or VHDL. Your submission is compiled and simulated against a real testbench — you get the waveform back, not a stored answer.
This problem is part of Codiode Pro. The statement above is free to read.
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.