0

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
delkov
  • 101

1 Answers1

1

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.

dave_59
  • 8,312
  • 1
  • 15
  • 27