RTL Reference
Blocking = and Nonblocking <=
A blocking assignment updates at once. A nonblocking assignment reads now and updates at the end of the time step.
Syntax
a = b; // blocking: a changes before the next statement
a <= b; // nonblocking: a changes after every right-hand side is readRules
- Use
<=for flops, inalways_ff. - Use
=for combinational logic, inalways_comb. - Do not mix both kinds for one variable.
- With
<=, the order of the statements does not change the result.
Example
module tb;
logic clk = 0;
logic [3:0] a = 1, b = 2; // swapped with <=
logic [3:0] c = 1, d = 2; // "swapped" with =
always @(posedge clk) begin
a <= b;
b <= a;
end
always @(posedge clk) begin
c = d;
d = c;
end
initial begin
#1 clk = 1; #1;
$display("nonblocking: a=%0d b=%0d", a, b);
$display("blocking: c=%0d d=%0d", c, d);
end
endmodulenonblocking: a=2 b=1
blocking: c=2 d=2Common Mistake
Reading a flop that another block wrote with =
always @(posedge clk) q1 = d;
always @(posedge clk) q2 = q1; // old q1 or new q1?Both blocks run on the same edge, in an order the standard does not fix. q2 can get either value, and two simulators can disagree.
Fix: Use <= in both blocks. q2 then always gets the old q1.
Learn It Properly
These lessons teach it step by step, with practice problems.
Standard
IEEE 1800-2023, 10.4.1 and 10.4.2.