Difficulty: Easy · Puzzle 5 of 6 · Topic: Event Scheduling Puzzles
Predict active print and end-of-slot value of q on the first edge. Explain why only one NBA survives.
module tb;
bit clk = 0;
int q = 0;
always #5 clk = ~clk;
always @(posedge clk) begin
q <= 1;
q <= 2;
q <= 3;
$display("[%0t ACTIVE] q=%0d", $time, q);
end
initial begin
@(posedge clk);
$strobe("[%0t POSTPONED] q=%0d", $time, q);
#1 $finish;
end
endmoduleWithin one process and one time slot, later NBA to same variable overrides earlier NBA updates.
1) Active print sees old q=0 at t=5.
2) Three NBAs are queued for q in same process.
3) Last assignment q<=3 overrides earlier q<=1 and q<=2 for that slot.
4) Postponed print shows q=3 at t=5.
5) The #1 before $finish keeps the strobe (Postponed region) out of the time slot where $finish runs, so every tool prints it.Answer: Active shows q=0 at t=5; final value is q=3 at t=5. Last NBA to same variable in the process wins.
Checked by running the code in Verilator 5 and Icarus Verilog 13; the printed output supports the answer above. Only the last NBA to q in the process survives: the final value is 3. Icarus agrees: the active print is the old q=0 and the end-of-slot value is 3.
People mix this with cross-process NBA ordering, which is not guaranteed.
What if each q<= assignment were in separate always blocks on the same edge?
The first print in Active shows the old q, which is 0, because NBAs have not been applied yet. Three NBAs to q from the same process are queued in order and the last one wins, so q ends at 3. The trap is mixing this with NBAs from different processes, where the order is not defined. I would check the strobe is not in the same slot as the finish, so every tool prints it.