RTL Design #68 · 2026-11-30 · Shifters · Easy · about 15 min
Registered shifter and rotator
shifter is a registered 8-bit shifter and rotator. On every rising edge where en is 1, it captures the result of one operation on din into dout, and dout_valid is 1 for the following clock. Otherwise dout keeps its value and dout_valid is 0.
mode picks the operation, and amt (0 to 7) is the number of positions:
mode |
operation |
|---|---|
| 0 | shift left, filling with 0s |
| 1 | shift right, filling with 0s |
| 2 | arithmetic shift right: din is a signed number, so copies of its top bit din[7] fill in from the left |
| 3 | rotate left: bits that leave on the left come back in on the right |
With amt 0, every mode returns din unchanged. On a rising edge where rst_n is 0 (synchronous reset), dout becomes 0 and dout_valid becomes 0; reset wins over en.
Example (rst_n is 1 throughout):
| edge | en |
mode |
amt |
din |
dout after the edge |
dout_valid after the edge |
|---|---|---|---|---|---|---|
| 1 | 1 | 3 | 3 | 1001_0110 |
1011_0100 |
1 |
| 2 | 0 | 0 | 1 | 0000_0001 |
1011_0100 |
0 |
| 3 | 1 | 2 | 2 | 1001_0110 |
1110_0101 |
1 |
Fill in shifter in shifter.sv.
Write and run your answer in the browser. The hidden tests check it, and it’s free.