19. Barrel shifter and rotator
Build a combinational 8-bit shifter that moves d by amt places (0 to 7) in one step.
dir = 0 moves bits towards the top (left); dir = 1 moves them towards the bottom (right). With rotate = 0 it is a logical shift: zeros come in. With rotate = 1 the bits that fall off one end come back in at the other.
Build it as a logarithmic shifter: three stages that shift by 1, 2 and 4 places, each enabled by one bit of amt.
Ports
| Port | Dir | Bits | What it is |
|---|---|---|---|
d | in | 8 | Value to shift. |
amt | in | 3 | Places to move, 0 to 7. |
dir | in | 1 | 0 left, 1 right. |
rotate | in | 1 | 1 rotates, 0 shifts in zeros. |
y | out | 8 | Result. |
Example
d = 1011_0100, amt = 3: shift left gives 1010_0000, rotate left gives 1010_0101, rotate right gives 1001_0110.
Written hints
AI hint
Submissions
No submissions yet. Submit your answer and it shows here. Sign in to keep them.
Submit your answer to have it graded. The hidden test runs on the server; you see whether it passes and, if not, the first case it gets wrong.
Press Build to check your code with Yosys. Errors and warnings show here, and a clean build draws the logic diagram.
Build your design to drive it by hand and see its signals here.