Verilog Nonblocking Assignments Demystified
Verilog Nonblocking Assignments Demystified
Clifford E. Cummings
Sunburst Design, Inc.
15870 SW Breccia Drive
Beaverton, OR 97007
cliffc@sunburst-design.com
Authorized licensed use limited to: NATIONAL INSTITUTE OF TECHNOLOGY DURGAPUR. Downloaded on July 17, 2009 at 11:17 from IEEE Xplore. Restrictions apply.
events are processed. These are the nonblocking 5. $strobe and $monitor commands
assign update events."
To show values after making nonblocking
This includes procedural assignments using the assignments, use either the $strobe command or the
nonblocking-assignment operator. $monitor command, both of which execute after a
nonblocking assignment has completed execution.
"4) Events that shall be processed after all the active,
inactive, and nonblocking assign update events are $strobe example:
processed. These are the monitor events."
module strobe_ivc;
This includes values displayed using either the reg a;
$monitor or $strobe commands.
initial begin
"5) Events that occur at some future simulation time. a = 0;
a <= 1;
These are the future events. Future events are divided
$strobe("$strobe: a = %b", a);
into future inactive events, and future nonblocking #1 $finish;
assignment update events." end
endmodule
4. $display command
Output display:
Verilog users often become confused when trying to
display values after making assignments using $strobe: a = 1
nonblocking assignments. In the earlier section describing
scheduling semantics, it is clear that if both a $display The value displayed by the $strobe command is the
command and a nonblocking assignment are scheduled in value that was assigned by the nonblocking assignment, a
the same simulation time-step, the $display command will <= 1;
complete before the nonblocking assignment has
completed. This can be confusing if a $display command $monitor example:
was placed immediately after a nonblocking assignment
module monitor_ivc;
since the displayed value will be the value before the
reg a;
nonblocking assignment has completed.
initial begin
$display example: a = 0;
a <= 1;
module display_ivc; $monitor("$monitor: a = %b", a);
reg a; #1 $finish;
end
initial begin endmodule
a = 0;
a <= 1; Output display:
$display("$display: a = %b", a);
#1 $finish; $monitor: a = 1
end
endmodule
The value displayed by the $monitor command is the
Output display: value that was assigned by the nonblocking assignment, a
<= 1;
$display: a = 0
6. #0 delays
The value displayed by the $display command is the An over-used and generally poor Verilog coding style
value that was assigned by the blocking assignment, a = is to make assignments with #0 delays. #0 is generally
0; not the updated value from the nonblocking believed to force assignments to occur at the end of a
assignment. simulation time-step and is most frequently used in
Authorized licensed use limited to: NATIONAL INSTITUTE OF TECHNOLOGY DURGAPUR. Downloaded on July 17, 2009 at 11:17 from IEEE Xplore. Restrictions apply.
Verilog models that make assignments to the same 7. Assignments in the same always block
variable from more than one procedural block.
A common misconception concerning nonblocking
This concept is flawed and the practice is over used. assignments is that if multiple nonblocking assignments
#0 causes assignments to occur later in one of the are made to the same variable, in the same procedural
assignment queues. block, during the same simulation time-step, that this
behavior is undefined in the Verilog language. This is not
Example: true.
module delay0_ivc; From IEEE Std 1364-1995 [2], pg. 47, section 5.4.1
reg a;
Determinism -
initial begin
#0 a = 0; "2) Nonblocking assignments shall be performed in
$display("#0 $display: a = %b", a); the order the statements were executed. Consider the
end following example:
initial a = 1; initial begin
a <= 0;
initial a <= 1'bx;
a <= 1;
initial $display("$display: a = %b", a); end
initial $strobe("$strobe: a = %b", a); When this block is executed, there will be two events
added to the nonblocking assign update queue. The
initial #1 $finish; previous rule requires that they be entered on the
endmodule queue in source order; this rule requires that they be
taken from the queue and performed in source order
Output display: as well. Hence, at the end of time-step 1, the variable
a will be assigned 0 and then 1."
$display: a = 1
#0 $display: a = 0
$strobe: a = x It is good synthesis and model coding style to make
an initial default assignment in an always block to output
The value displayed by the second $display variables using nonblocking assignments, and then to
command was the value that was assigned by the blocking update specific assignments within the block as
assignment, a = 1;. The value displayed by the first functionally appropriate.
$display command was the value that was assigned by the
#0 blocking assignment, #0 a = 0;. The value displayed by This coding style, in general, makes model-code
the $strobe command was the value that was assigned by more compact and easy to follow, since the default output
the nonblocking assignment, a <= 1'bx; therefore, the #0 assignments are at the beginning of the always block and
command only insured that the #0-blocking assignment it is easy to scan the rest of the block to see where a
was executed at the end of the blocking assignment specific output is assigned.
queue, but before the nonblocking assignment was
executed. References
In general, it is poor coding practice to make [1] IEEE Copyright Form, http://www.ieee.org/copyright
assignments to the same variable from multiple always
blocks. To compensate for this poor coding practise, [2] IEEE Standard Hardware Description Language Based on
engineers use the #0 delay in an attempt to coerce the Verilog Hardware Description Language, IEEE Computer
assignment-order to the same variable from multiple Society, IEEE Std 1364-1995
always blocks or to delay a specific assignment from
occurring until after the assignment input variable has
been updated by another always block. This coding
practice is one source of Verilog race conditions and
should be discouraged.
Authorized licensed use limited to: NATIONAL INSTITUTE OF TECHNOLOGY DURGAPUR. Downloaded on July 17, 2009 at 11:17 from IEEE Xplore. Restrictions apply.