Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to interpret blocking vs non blocking assignments in Verilog?

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 
like image 484
infinitloop Avatar asked Jan 11 '11 01:01

infinitloop


People also ask

How are blocking assignments different from non-blocking assignments?

"blocking" and "nonblocking" assignments only exist within always blocks. A blocking assignment takes affect immediately it is processed. A nonblocking assignment takes place at the end of processing the current "time delta".

What is blocking and non-blocking assignment in Verilog?

• Verilog supports two types of assignments within always. blocks, with subtly different behaviors. • Blocking assignment: evaluation and assignment are immediate. • Nonblocking assignment: all assignments deferred until all. right-hand sides have been evaluated (end of simulation.

When would you use blocking vs non-blocking assignments when coding sequential logic?

Guideline #1: When modeling sequential logic, use nonblocking assignments. Guideline #2: When modeling latches, use nonblocking assignments. There are many ways to code combinational logic using Verilog, but when the combinational logic is coded using an always block, blocking assignments should be used.

How would you execute blocking and non-blocking statements?

Statements are executed sequentially in each block and both blocks finish at time 0ns. To be more specific, variable is assigned first, that followed by the display statement which is then followed by all other statements. This is visible in the output where variable b and c are 8'hxx in the first display statement.


1 Answers

The conventional Verilog wisdom has it all wrong. There is no problem with using blocking assignments for a local variable. However, you should never use blocking assignments for synchronous communication, as this is nondeterministic.

A non-blocking assignment within a clocked always block will always infer a flip-flop, as dictated by the semantics.

Whether a blocking assignment within a clocked always block infers a flip-flop or not depends entirely on how it is used. If it is possible that the variable is read before being assigned, a flip-flop will be inferred. Otherwise, this is like a temporary variable and it will result in some combinatorial logic.

like image 72
Jan Decaluwe Avatar answered Sep 27 '22 15:09

Jan Decaluwe