In Verilog, blocking and non-blocking assignments are two distinct ways to assign values to variables within procedural blocks (like always
blocks). They have significant implications for how your Verilog code simulates and synthesizes.
Blocking Assignment (=
)
reg a, b, c;
always @ (posedge clk) begin
a = 1; // Assign 1 to a
b = a; // Assign the current value of a (which is now 1) to b
c = b; // Assign the current value of b (which is 1) to c
end
In this example, a
is assigned 1 first. Then, b
is assigned the current value of a
, which is 1. Finally, c
is assigned the current value of b
, which is also 1.
Non-Blocking Assignment (<=
)
reg a, b, c;
always @ (posedge clk) begin
a <= 1;
b <= a;
c <= b;
end
In this example :
a
is scheduled to be assigned 1.b
is scheduled to be assigned the current value of a
(which is its previous value).c
is scheduled to be assigned the current value of b
(which is its previous value).