0
\$\begingroup\$

Is there any difference between nonblocking and blocking assignment for the following counters?

module  nonblocking_counter (
  input clk,               
  input rstn,              
  output reg[3:0] out
);    

  always @ (posedge clk) begin
    if (! rstn)
      out <= 0;
    else 
      out <= out + 1;
  end
endmodule

module  blocking_counter (
    input clk,              
    input rstn,
    output reg[3:0] out              
);   

  always @ (posedge clk) begin
    if (! rstn)
      out = 0;
    else 
      out = out + 1;
  end
endmodule
\$\endgroup\$
1
\$\begingroup\$

The circuit generated by synthesis tools will be identical for this code. However in simulation, you have a race condition on the output that feeds the input of another synchronized process when using blocking assignments.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.