RTL Design #35 · 2026-10-28 · Remainder FSMs · Easy · about 10 min

A remainder tracker that drops the first bit

mod3 receives a number one bit at a time, most significant bit first, and reports its remainder when divided by 3.

  • On a rising edge with valid = 1, din is the next bit. With start = 1 as well, it is the first bit of a new number, and whatever came before is forgotten.
  • After each accepted bit, rem is the remainder of all the bits of the current number so far (0, 1 or 2). rem holds while valid = 0, and start is ignored without valid.
  • rst_n = 0 (synchronous) clears rem to 0.
  • Numbers can follow each other with no idle cycle in between, and a number can be a single bit.

Run sends four numbers and some of the remainders come out wrong. Fix mod3.sv. Grading uses three hidden checks.

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