SystemVerilog #70 · 2026-12-02 · Expression width · Easy · about 15 min
A fixed-point multiply that loses its top half
Write qmul, a combinational multiplier for unsigned fixed-point numbers with 8 fraction bits (the value of a 16-bit word w is w / 256). The inputs a and b are 16 bits wide, and so is the output y.
y is the exact product, truncated to 8 fraction bits (the low 8 bits of the full product are dropped, not rounded). If that result is too large for 16 bits, y is 16'hFFFF instead. So y = min((a * b) / 256, 65535), computed as if there were no width limits along the way.
Examples: 16'h0080 (0.5) times 16'h0100 (1.0) gives 16'h0080. 16'h0010 times 16'h0300 gives 16'h0030. 16'h00FF times 16'h0100 gives 16'h00FF.
Fill in qmul.sv. Run tries five pairs.
Write and run your answer in the browser. The hidden tests check it, and it’s free.