A random test of the ALU passes on most seeds and fails on seed 4. Find the first bad cycle and signal, name the bug, and fix the ALU.
Hardware context: The same ALU driven by a seeded random generator. Replaying a failure from a nightly regression.
A random test drives the ALU with one operation per clock, 300 draws from one seed. It compares every result with a reference model. Many seeds pass. Seed 4 fails, and because the seed is recorded, the failure is the same on every run.
Run the failing test below and read its log and its waveform.
Step 1: find the first cycle where y, c or z differs from the specification, and name the signal. Step 2: choose the cause. Step 3, optional: fix alu8; the fix is graded by the normal rows.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
scenario | 8 | input of each check |
Full specification
// alu8: an 8-bit ALU. op: 0 ADD, 1 SUB, 2 AND, 3 XOR (4 to 7 are reserved and give 0).
// c is the carry out of ADD or the borrow of SUB. z is 1 when y is 0.
module alu8 (input logic [2:0] op, input logic [7:0] a, b, output logic [7:0] y, output logic c, z);
...
endmodule
| op | y | c | z |
|---|---|---|---|
| 0 ADD | (a + b) mod 256 | 1 when a + b is 256 or more | 1 when y is 0 |
| 1 SUB | (a - b) mod 256 | 1 when a < b | 1 when y is 0 |
| 2 AND | a & b | 0 | 1 when y is 0 |
| 3 XOR | a ^ b | 0 | 1 when y is 0 |
| 4 to 7 | 0 | 0 | 1 |
Cycle N is the clock after the N-th rising edge. Inputs change at the falling edge; the bench compares at the next rising edge.
Diagnose the Failing Run
The test below runs the buggy design. Read its log, then find where it first goes wrong in the waveform.
Log
Waveform
Click a signal at a cycle to select it. Or focus the waveform and use the arrow keys: Left and Right move one cycle, Up and Down one signal.
Step 3 is optional: fix the code in the editor, then run the tests.
Examples
Example 1
ADD: Small, a Carry from the Low Bits, a Sum of 256- Input
ADD 3, 4; ADD 200, 100; ADD 64, 192; ADD 255, 1; ADD 0, 0; ADD 129, 1
- Output
vector1 = 0x1c, vector2 = 0xb2, vector3 = 0x3, vector4 = 0x3, vector5 = 0x1, vector6 = 0x208
Each vector shows {y, c, z} as one hex number: y in the top eight bits, then c, then z. 255 + 1 gives y = 0, c = 1, z = 1: hex 003.
Example 2
SUB: No Borrow, a Borrow, Equal Values- Input
SUB 9, 4; SUB 2, 5; SUB 5, 5; SUB 0, 0; SUB 255, 0; SUB 0, 255
- Output
vector1 = 0x14, vector2 = 0x3f6, vector3 = 0x1, vector4 = 0x1, vector5 = 0x3fc, vector6 = 0x6
2 - 5 borrows: y = 253, c = 1, z = 0, hex 3f6. 5 - 5 gives zero with no borrow: hex 001.
Example 3
AND: Results with and Without Bit 7- Input
AND 240, 15; AND 128, 255; AND 255, 255; AND 0, 0; AND 192, 128; AND 127, 128
- Output
vector1 = 0x1, vector2 = 0x200, vector3 = 0x3fc, vector4 = 0x1, vector5 = 0x200, vector6 = 0x1
F0 & 0F is zero: hex 001. 80 & FF keeps bit 7: y = 128, z = 0, hex 200.
Constraints and Contract
- Keep the module name and the ports.
- The design is combinational: no clock.
Hints
Hint 1
Read the first ERROR line: which output disagrees, and for which operation?
Hint 2
Each cause shows first on a different operation and a different flag. Compare the inputs of that cycle with the table.
Hint 3
Write the operands of the failing cycle in binary.
What the grader checks: The failing run is simulated live with the shipped ALU and the seed shown. The fix is graded on six rows of six vectors each, 1 ns apart, compared with the specification as {y, c, z}. Reserved codes are part of the rows.
6 checks on Icarus · browser samples / server checks. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain public samples only. A passing result establishes the tested cases, not a proof for all possible inputs.
See all 2 problems on this path