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 + b is in the range −128 to 127, sum is a + b and sat is 0.
  • If a + b is more than 127, sum is 127 and sat is 1.
  • If a + b is less than −128, sum is −128 and sat is 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.