In the 2nd $display
, since you have put the display in another timeslot (with #1
), the updated value of A
& B
will be printed.
module blocking;
reg[0:7] A, B;
initial begin
A = 3;
#1 A = A + 1;
B = A + 1;
$display("Blocking: A = %0d B = %0d", A, B ); // A = 4, B = 5
A = 3;
#1 A <= A + 1;
B <= A + 1;
#1 $display("Non-blocking: A = %0d B = %0d", A, B ); // A = ?, B = ?
end
endmodule
Output:
Blocking: A = 4 B = 5
Non-blocking: A = 4 B = 4
But if you put the $display
in the same timeslot (without #1
), then the unupdated values of A
& B
will be printed.
module blocking;
reg[0:7] A, B;
initial begin
A = 3;
#1 A = A + 1;
B = A + 1;
$display("Blocking: A = %0d B = %0d", A, B ); // A = 4, B = 5
A = 3;
#1 A <= A + 1;
B <= A + 1;
$display("Non-blocking: A = %0d B = %0d", A, B ); // A = ?, B = ?
end
endmodule
Output:
Blocking: A = 4 B = 5
Non-blocking: A = 3 B = 5
The reason for that is scheduling of events in Verilog.
$display
is scheduled in the active region, which is before the NBA (Non Blocking Assignment) region and hence it will have the original values of the nonblocking assigned signals in the same timeslot.