RTL Design #52 · 2026-11-14 · Restoring divider · Medium · about 30 min

Build an 8-bit restoring divider

Write divider, an 8-bit unsigned restoring divider that produces one quotient bit per clock. It computes q = a / b and r = a % b.

  • Start. If start is 1 on a rising edge while busy is 0, the divider captures a and b and begins. A start that arrives while busy is 1 is ignored. Inputs a and b may change right after the start edge.
  • Timing. busy is 1 for exactly 8 clocks after the start edge, one per quotient bit, most significant bit first. In the clock after that, busy is 0 and done is 1 for exactly one clock, and q and r hold the result during that clock. q and r are not checked at any other time.
  • Divide by zero. If b is 0, the timing is the same, and the result is q = 8'hFF, r = a.
  • Back to back. A start in the clock where done is 1 is accepted.
  • Reset. Synchronous, active low. It clears busy and done and abandons any division in progress.

The restoring algorithm: keep a partial remainder, shift in the next bit of a, subtract b if the result is at least b (the quotient bit is then 1), otherwise keep it (the bit is 0).

Example, a = 13, b = 4, with start high only in clock 0:

clock 0 1 – 8 9 10
busy 0 1 0 0
done 0 0 1 0
q, r 3, 1

testbench.sv runs one division and prints PASS when it works. Submit runs hidden checks on ordinary and extreme operands, divide by zero, restarts, and reset.

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