Blocking vs Non-Blocking Assignment in Verilog: Key Differences
Both are assignments used inside Verilog always blocks, but they differ in when the left-hand side is updated. A blocking assignment (=) updates the left-hand side as soon as the line executes, and the next line sees the new value. A non-blocking assignment (<=) first evaluates all right-hand sides at the same time step, then updates the left-hand sides together. The basic guideline is <= for clocked sequential logic and = for combinational always blocks.
| Aspect | Blocking assignment (=) | Non-blocking assignment (<=) |
|---|---|---|
| Syntax | a = b; | a <= b; |
| When the left-hand side is updated | Immediately, when the line executes | Together, after all right-hand sides at the same time step have been evaluated |
| Value seen by the next line | The new, updated value | The old value before the update |
| Dependence on statement order | Yes. Swapping lines changes the result | Almost none. However, if the same variable is assigned twice, the later assignment wins |
| Corresponding hardware behavior | Combinational logic that computes intermediate values in order from top to bottom | Flip-flops that all capture values at the same clock edge |
| Where it is mainly used | Combinational always @(*), testbench procedures | Clocked sequential always @(posedge clk) |
| Two-stage shift register (clocked block) | With q1 = d; q2 = q1; q2 also gets d at the same edge, giving only one stage of delay | With q1 <= d; q2 <= q1; q2 gets q1 from before the edge, giving two stages |
| Swapping values (clocked block) | With a = b; b = a; a and b end up with the same value | With a <= b; b <= a; a and b are swapped |
| Across multiple always blocks | Blocks triggered by the same edge are prone to races where the result depends on execution order | All right-hand sides are evaluated first, so races are unlikely |
| When misused | In sequential logic, the result depends on block execution order and may differ from the synthesized circuit | In combinational logic, intermediate values are read while still stale, so simulation may differ from the synthesized circuit or blocks re-execute unnecessarily |
Figures are typical orders of magnitude and vary by process generation and product.