RTL Design #13 · 2026-10-06 · Shifters · Medium · about 10 min

A shifter that loses the sign

shifter shifts the 8-bit value a by amt places (0 to 7), combinationally. op picks the operation:

  • 0: shift left. Zeros come in at the bottom.
  • 1: logical shift right. Zeros come in at the top.
  • 2: arithmetic shift right. a is treated as a signed number, so copies of its sign bit a[7] come in at the top: −80 shifted by 2 is −20.
  • 3: rotate left. The bits that leave the top come back in at the bottom.

Run tries seven shifts. The arithmetic ones come out wrong whenever a is negative. Fix shifter.sv.

Write and run your answer in the browser. The hidden tests check it, and it’s free.