RTL Design #12 · 2026-10-05 · Arithmetic · Easy · about 10 min
A saturating adder that clamps at the wrong time
sat_add adds two 8-bit signed numbers, combinationally. Where an ordinary adder would wrap around, it clamps:
- If
a + bis in the range −128 to 127,sumisa + bandsatis 0. - If
a + bis more than 127,sumis 127 andsatis 1. - If
a + bis less than −128,sumis −128 andsatis 1.
Run tries nine pairs. Some sums that fit come out clamped, and some that don't fit come out wrapped. Fix sat_add.sv.
Write and run your answer in the browser. The hidden tests check it, and it’s free.