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
"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".
• 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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With