I am a little confused about how blocking and non blocking assignments are interpreted when it comes to drawing a hardware diagram. Do we have to infer that a non blocking assignment gives us a register? Then according to this statement c <= a+b , c would be a register right, but not a and b?
module add (input logic clock,
output logic[7:0] f);
logic[7:0] a, b, c;
always_ff @(posedge clock)
begin
a = b + c;
b = c + a;
c <= a + b;
end
assign f = c;
endmodule
It’s definitely a bit tricky to get your head around the differences between blocking and nonblocking assignments initially. But no fear – there’s a handy rule of thumb:
Your code above is probably not the best example. Without knowing what adder/flipflop structure you were trying to build, there’s the danger of having combo feedback paths (which are bad). And since you’ve no input buses, you’re essentially trying to construct
a,b&cout of thin air!But to answer your question, any variable assigned to within a clocked
alwaysblock will infer a flipflop, unless its assigned using the blocking operator (=) and used as a kind of a local variable.A big reason for following the rule of thumb and not mixing blocking and nonblocking assignments within an
alwaysblock, is that mixing your assignments can cause serious simulation mismatches between RTL sims and gate-sims/real hardware operation. The verilog simulator treats=and<=quite differently. Blocking assignments mean ‘assign the value to the variable right away this instant’. Nonblocking assignments mean ‘figure out what to assign to this variable, and store it away to assign at some future time’. A good paper to read to understand this better is: Also see: http://www.sunburst-design.com/papers/CummingsSNUG2000SJ_NBA.pdf