Verilog Blocking vs Nonblocking Assignments
Learn when to use = and <= in Verilog, how nonblocking updates are scheduled, and how to avoid simulation races in RTL.
The rule to remember
Use blocking assignment (=) for combinational calculations and nonblocking assignment (<=) for registers updated by a clocked process. The symbols do not create hardware by themselves—the process sensitivity and assignment completeness also matter—but this rule makes simulation behavior match the intended hardware.
Why the results differ
A blocking assignment updates its left-hand side immediately, before the next statement in the same process executes. A nonblocking assignment evaluates its right-hand side now and schedules the update for the nonblocking-assignment region later in the current simulation time step.
always @(posedge clk) begin
stage1 <= data_in;
stage2 <= stage1;
end
Both right-hand sides use values sampled before either register is updated. This models two pipeline registers. Replacing <= with = makes stage2 see the newly assigned stage1 in simulation and collapses the apparent pipeline.
For combinational logic, ordered temporary calculations are clearer with blocking assignments:
always @* begin
sum = a + b;
flag = (sum == 8'h00);
end
Race prevention
Do not rely on the execution order of separate always blocks triggered in the same time slot. Drive clocked RTL with nonblocking assignments, and make a testbench drive inputs away from the DUT sampling edge or through a SystemVerilog clocking block. Avoid mixing blocking and nonblocking assignments to the same variable.
Review checklist
- Clocked state uses
<=. - Combinational outputs receive a value on every path and normally use
=. - A signal has one clear procedural owner.
- The testbench does not race the DUT at the active clock edge.