Turn the ALU's feature list into at most ten directed cases, each with an answer you work out by hand. Every feature must be reached, and every answer must be right.
Hardware context: An 8-bit ALU with carry, borrow and zero flags. Bring-up tests for a new datapath block.
A directed test reads a feature, picks inputs that use it, and states the right answer before the run. Here you write such a list for the 8-bit ALU of the lesson. You do not write the ALU, and you do not run it: your answers come from its specification.
In the task directed, call expect_alu once per case: expect_alu(op, a, b, y, c, z). The check compares each answer with the specification. Then it asks whether a case with a right answer reached each of the eight features below. Use at most ten calls.
Private rows run your list against ALUs with planted bugs. A list that reaches every feature with right answers catches them.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
scenario | 8 | input of each check |
Full specification
| op | Operation | 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 (a borrow) | 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 |
Codes 4 to 7 are reserved: a case with one of them is a wrong answer.
| Feature | Reached when |
|---|---|
| 1 | ADD with no carry and a result that is not zero (op == 0 and a + b < 256 and a + b != 0) |
| 2 | ADD with a carry and a result that is not zero (op == 0 and a + b > 256) |
| 3 | ADD whose sum is exactly 256 (op == 0 and a + b == 256) |
| 4 | SUB with no borrow and a result that is not zero (op == 1 and a > b) |
| 5 | SUB of two equal values (op == 1 and a == b) |
| 6 | SUB with a borrow (op == 1 and a < b) |
| 7 | AND of two values that are not zero, giving zero (op == 2 and a != 0 and b != 0 and (a & b) == 0) |
| 8 | XOR of two equal values that are not zero (op == 3 and a == b and a != 0) |
task automatic directed();
expect_alu(0, 3, 4, 7, 0, 0); // ADD, no carry: 3 + 4 = 7
endtask
Examples
Example 1
Every Answer Is Right, Within the Budget- Input
Your calls, each answer compared with the specification
- Output
within_budget = yes, wrong_answers = 0
Every answer is compared with the specification. A wrong answer, a reserved code, or more than ten calls fails this row.
Example 2
Feature 1: ADD with No Carry and a Result That Is Not Zero- Input
Some call within the budget reaches it with a right answer
- Output
reached_with_a_right_answer = yes
Some call must be an ADD with no carry and a result that is not zero, such as 3 + 4.
Example 3
Feature 2: ADD with a Carry and a Result That Is Not Zero- Input
Some call within the budget reaches it with a right answer
- Output
reached_with_a_right_answer = yes
Some call must be an ADD that carries without giving zero, such as 200 + 100 = 44 with a carry.
Constraints and Contract
- Write only the task directed, with at most ten calls of expect_alu.
- Numbers may be written in decimal or hex, such as 8'hF0.
Hints
Hint 1
One case per feature is enough: eight calls.
Hint 2
For ADD to exactly 256, the 8-bit result is 0 and the carry is 1. Work out z from y, not from the carry.
Hint 3
A borrow happens when a < b; the result wraps round, so 2 - 5 gives 253.
What the grader checks: The check records each call of expect_alu and compares its answer with the specification of the ALU. A feature row passes when a call within the first ten reaches it with a right answer. Three private rows run the same calls against ALUs with one planted bug each. Comments, and how you found the answers, are not seen.
12 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 1 problem on this path