Three assertions are clocked by a code and its delayed copy. Say when each one fails, and what it read.
Hardware context: An error code bus and a halt line with no common clock. Find what an assertion clocked by the bus itself really reads, and when it reports.
The rule: whenever code holds the error code 14, halt is high. The main program writes it three ways. naive is clocked by code itself. kept and fixed are clocked by a copy of code delayed by 2.
Write answer(q). Questions 3 to 7 ask for failure times, a printed value and a count.
Questions 0 to 2 are worked examples on a smaller program. Questions 3 to 7 are graded only by the full check.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
question | 4 | input of each check |
Full specification
module tb;
localparam logic [3:0] ERR = 4'd14;
logic [3:0] code = 4'd0;
logic halt = 0;
logic [3:0] code_d;
assign #2 code_d = code; // code, two time units later
naive: assert property (@(code) code == ERR |-> halt)
else $display("naive fails at %0t: code=%0d", $time, $sampled(code));
kept: assert property (@(code_d) code_d == ERR |-> halt)
else $display("kept fails at %0t", $time);
fixed: assert property (@(code_d) code == ERR |-> halt)
else $display("fixed fails at %0t", $time);
initial begin
#10 code = ERR; halt = 1; // t=10: legal
#10 code = 4'd2; halt = 0; // t=20
#10 code = ERR; // t=30: no halt
#5 halt = 1; // t=35
#5 code = 4'd5; // t=40
#5 halt = 0; // t=45
#5 code = ERR; // t=50: no halt
#10 code = 4'd7; // t=60
#10 $finish; // t=70
end
endmodule
| q | Return | Program |
|---|---|---|
| 0 | the time of the first failure of busy_rule | worked example |
| 1 | the value of st it prints | worked example |
| 2 | how many times busy_rule fails | worked example |
| 3 | the time of the first failure of naive | main, graded |
| 4 | the value of code it prints | main, graded |
| 5 | how many times naive fails | main, graded |
| 6 | the time of the first failure of fixed | main, graded |
| 7 | the time of the first failure of kept | main, graded |
module tb;
logic [1:0] st = 2'd0;
logic ready = 1;
busy_rule: assert property (@(st) st == 2'd2 |-> !ready)
else $display("busy_rule fails at %0t: st=%0d", $time, $sampled(st));
initial begin
#8 st = 2'd2; ready = 0; // t=8: legal
#6 st = 2'd1; // t=14
#2 ready = 1; // t=16
#4 st = 2'd2; // t=20: ready still high
#9 st = 2'd3; // t=29
#6 $finish; // t=35
end
endmodule
Simulator note: The key was measured on Verilator 5.052 and agrees with IEEE 1800-2023 16.5.1. Your answer function is checked by a small bench on Icarus 12.
Examples
Example 1
Find the Failing Change- Input
answer(0)
- Output
answer = 29
At 29, st leaves 2 while ready is high. The assertion reads st as 2 there.
Example 2
The Value It Read- Input
answer(1)
- Output
answer = 2
$sampled(st) in the action block is the value st had before the change: 2.
Example 3
Count Them- Input
answer(2)
- Output
answer = 1
At 20, st becomes 2 with ready high, but the assertion reads the old value 1 and stays vacuous.
Constraints and Contract
- Return one value per question from answer(q).
- Keep the function header.
Hints
Hint 1
List every change of code and of code_d. Each one starts an attempt of the assertions it clocks.
Hint 2
An assertion reads sampled values: the values from before the time step of its event.
Hint 3
At a change of code, the sampled code is the value it is leaving.
What the grader checks: Eight constant answers: three worked examples and five graded questions. They are graded against values measured on Verilator 5.052 and derived by hand from the standard.
8 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 steps and the final capstone