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
startis 1 on a rising edge whilebusyis 0, the divider capturesaandband begins. Astartthat arrives whilebusyis 1 is ignored. Inputsaandbmay change right after the start edge. - Timing.
busyis 1 for exactly 8 clocks after the start edge, one per quotient bit, most significant bit first. In the clock after that,busyis 0 anddoneis 1 for exactly one clock, andqandrhold the result during that clock.qandrare not checked at any other time. - Divide by zero. If
bis 0, the timing is the same, and the result isq = 8'hFF,r = a. - Back to back. A
startin the clock wheredoneis 1 is accepted. - Reset. Synchronous, active low. It clears
busyanddoneand 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.