1
\$\begingroup\$
module t;
reg a;
initial a <= #4 0;
initial a <= #4 1;
initial $monitor ($time,,"a = %b", a);
endmodule

Output of above Verilog code is:

 0 a = x
 4 a = 1

When I added initial a = 1;, more changes happened, but $monitor outputs less:

module t;
reg a;
initial a = 1;
initial a <= #4 0;
initial a <= #4 1;
initial $monitor ($time, ,"a = %b", a);
endmodule

Output of above Verilog code is:

 0 a = x
 

How blocking assignment initial a = 1 affect non-blocking assignment in Verilog?

toolic
10.8k11 gold badges31 silver badges35 bronze badges
asked Jun 26 at 15:26
\$\endgroup\$
1
  • \$\begingroup\$ Is $monitor a non blocking assignment update event? \$\endgroup\$ Commented Jun 26 at 15:43

1 Answer 1

1
\$\begingroup\$

Refer to IEEE Std 1800-2023, section 21.2.3 Continuous monitoring:

When a $monitor task is invoked with one or more arguments, the simulator sets up a mechanism whereby each time a variable or an expression in the argument list changes value—with the exception of the $time, $stime, or $realtime system functions—the entire argument list is displayed at the end of the time step as if reported by the $display task.

In your second code example, a only changes value once. At time=0, it changes from x to 1 in this line:

initial a = 1;

This is what is displayed by your simulator.

The other 2 assignments:

initial a <= #4 0;
initial a <= #4 1;

assign a to 0 then back to 1 at time=4. However, there is no net change to a, so $monitor has no change in value to display.


You should avoid making multiple assignments to the same signal at the same time to avoid such behavior as this. Your code does not follow standard good Verilog coding practices.

Note: when I run the 2nd code example on 3 different simulators, I get this result:

0 a = 1

Since you get a different result, this is likely a simulation race condition, which is yet another reason not to write code like this.

answered Jun 26 at 16:24
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.