Level 43: Freezing Time

Open the level →

Task

The FullAdder module has a bug — one of the wires is connected incorrectly. Some tests fail. Find the error, fix it, and get all tests passing.

File fulladder.v is editable. cpu.v and testbench.v are read-only (context). Use the tabs to switch between files.

Hint: look closely at gate g4 — which signal should it process for correct carry generation c_out?

Related materials

Solution

How to read a waveform and find the bug: 1. Find the moment where the test result diverges from the expected one (the first mismatch on sum or c_out). 2. Look at the internal wires at that same moment — which signal behaves incorrectly. 3. Walk backwards from the output to the source: c_outw2/w3 → gates → inputs. The bug always lives in the gate whose output does not match the formula. See the Timing Diagram article.

In file fulladder.v, the error is in gate g4:

and g4(w3, w1, w2);  // bug — third port is w2 instead of c_in

Fix:

and g4(w3, w1, c_in);  // correct — w3 = w1 AND c_in

Signal w3 contributes to the output carry: c_out = w2 OR w3, where w2 = a AND b. Full formula: c_out = (a AND b) OR ((a XOR b) AND c_in) — the classical full adder logic. Using w2 instead of c_in produces incorrect results.

Solution circuit for level 43 — Freezing Time
The authored solution for level 43 in the simulator (dark theme)