Write the ALU's coverage model in plain code. Drop every transaction into its bin of the cross, ignore reserved codes, and count the holes.
Hardware context: The ALU's operations crossed with the kinds of result. Closing a hole with a constraint or a directed case.
The lesson counted hits in a table of counters. Here you write that table as a small module, the way a bench would carry it. Each transaction the bench checks is passed to sample. After a run, holes says how many bins that can happen were never reached.
The bin of a transaction comes from its expected result, worked out from the specification: the zero flag and the carry. Reserved codes 4 to 7 are not legal transactions and are not counted.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
scenario | 8 | input of each check |
Full specification
| op | y | c |
|---|---|---|
| 0 ADD | (a + b) mod 256 | 1 when a + b is 256 or more |
| 1 SUB | (a - b) mod 256 | 1 when a < b |
| 2 AND | a & b | 0 |
| 3 XOR | a ^ b | 0 |
| k = {z, c} | Result kind | Can happen for |
|---|---|---|
| 0 | ordinary | every operation |
| 1 | carry, not zero | ADD, SUB |
| 2 | zero, no carry | every operation |
| 3 | zero and carry | ADD only (a sum of exactly 256) |
z is 1 when y is 0. So 16 pairs of operation and kind become 11 bins that can happen. holes() counts the empty ones among those 11 only.
Examples
Example 1
Six Hand-Picked Transactions- Input
6 transactions
- Output
holes = 5, add_ordinary = 1, add_carry = 1, add_zero = 0, add_zero_carry = 0, sub_ordinary = 1, sub_carry = 0, sub_zero = 1, and_ordinary = 0, and_zero = 1, xor_ordinary = 0, xor_zero = 1
Six transactions land in six different bins; XOR 7 ^ 7 lands in xor_zero. Six of the 11 bins are filled, so 5 holes remain. Counts above 15 are shown as 15.
Example 2
Sums of Exactly 256, and 0 + 0- Input
4 transactions
- Output
holes = 8, add_ordinary = 0, add_carry = 0, add_zero = 1, add_zero_carry = 2, sub_ordinary = 0, sub_carry = 1, sub_zero = 0, and_ordinary = 0, and_zero = 0, xor_ordinary = 0, xor_zero = 0
255 + 1 and 128 + 128 sum to 256: zero and carry together. 0 + 0 is zero with no carry. 2 - 5 borrows.
Example 3
Reserved Codes in the Stream Are Not Counted- Input
5 transactions
- Output
holes = 10, add_ordinary = 1, add_carry = 0, add_zero = 0, add_zero_carry = 0, sub_ordinary = 0, sub_carry = 0, sub_zero = 0, and_ordinary = 0, and_zero = 0, xor_ordinary = 0, xor_zero = 0
Codes 4 to 7 are skipped; only 1 + 1 is counted, so 10 holes remain.
Constraints and Contract
- Keep the module name, hits[4][4], sample and holes.
- The bench clears hits between rows.
Hints
Hint 1
Work out y and c in nine bits, as the ALU does; z comes from the low eight bits only.
Hint 2
Count nothing when op is above 3.
Hint 3
AND and XOR never carry, and a borrow never leaves zero: leave those five pairs out of holes.
What the grader checks: Six streams of transactions, each starting from cleared counters. Each row reports holes() and the 11 bins that can happen, each count capped at 15 for the report. The five pairs that cannot happen are not read.
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