Verilog Blocking & Non-Blocking

Blocking assignment statements are assigned using = and are executed one after the other in a procedural block. However, this will not prevent execution of statments that run in a parallel block.

Note that there are two initial blocks which are executed in parallel when simulation starts. Statements are executed sequentially in each block and both blocks finish at time 0ns. To be more specific, variable a gets assigned first, 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. This is because variable b and c assignments have not been executed yet when the first $display is called.

In the next example, we'll add a few delays into the same set of statements to see how it behaves.

Non-blocking

Non-blocking assignment allows assignments to be scheduled without blocking the execution of following statements and is specified by a symbol. It's interesting to note that the same symbol is used as a relational operator in expressions, and as an assignment operator in the context of a non-blocking assignment. If we take the first example from above, replace all = symobls with a non-blocking assignment operator , we'll see some difference in the output.

See that all the $display statements printed 'h'x . The reason for this behavior lies in the way non-blocking assignments are executed. The RHS of every non-blocking statement of a particular time-step is captured, and moves onto the next statement. The captured RHS value is assigned to the LHS variable only at the end of the time-step.

So, if we break down the execution flow of the above example we'll get something like what's shown below.

Next, let's use the second example and replace all blocking statements into non-blocking.

Once again we can see that the output is different than what we got before.

If we break down the execution flow we'll get something like what's shown below.

DMCA.com Protection Status

GitHub

Blocking vs. Nonblocking in Verilog

The concept of Blocking vs. Nonblocking signal assignments is a unique one to hardware description languages. The main reason to use either Blocking or Nonblocking assignments is to generate either combinational or sequential logic. In software, all assignments work one at a time. So for example in the C code below:

The second line is only allowed to be executed once the first line is complete. Although you probably didn’t know it, this is an example of a blocking assignment. One assignment blocks the next from executing until it is done. In a hardware description language such as Verilog there is logic that can execute concurrently or at the same time as opposed to one-line-at-a-time and there needs to be a way to tell which logic is which.

<=     Nonblocking Assignment

=      Blocking Assignment

The always block in the Verilog code above uses the Nonblocking Assignment, which means that it will take 3 clock cycles for the value 1 to propagate from r_Test_1 to r_Test_3. Now consider this code:

See the difference? In the always block above, the Blocking Assignment is used. In this example, the value 1 will immediately propagate to r_Test_3 . The Blocking assignment immediately takes the value in the right-hand-side and assigns it to the left hand side. Here’s a good rule of thumb for Verilog:

In Verilog, if you want to create sequential logic use a clocked always block with Nonblocking assignments. If you want to create combinational logic use an always block with Blocking assignments. Try not to mix the two in the same always block.

Nonblocking and Blocking Assignments can be mixed in the same always block. However you must be careful when doing this! It’s actually up to the synthesis tools to determine whether a blocking assignment within a clocked always block will infer a Flip-Flop or not. If it is possible that the signal will be read before being assigned, the tools will infer sequential logic. If not, then the tools will generate combinational logic. For this reason it’s best just to separate your combinational and sequential code as much as possible.

One last point: you should also understand the semantics of Verilog. When talking about Blocking and Nonblocking Assignments we are referring to Assignments that are exclusively used in Procedures (always, initial, task, function). You are only allowed to assign the reg data type in procedures. This is different from a Continuous Assignment . Continuous Assignments are everything that’s not a Procedure, and only allow for updating the wire data type.

Leave A Comment Cancel reply

Save my name, email, and website in this browser for the next time I comment.

  • Getting started with verilog
  • Hello World
  • Procedural Blocks
  • Non-blocking assignments
  • Simple counter
  • Synthesis vs Simulation mismatch

verilog Procedural Blocks Non-blocking assignments

A non-blocking assignment ( <= ) is used for assignment inside edge-sensitive always blocks. Within a block, the new values are not visible until the entire block has been processed. For example:

Notice the use of non-blocking ( <= ) assignments here. Since the first assignment doesn't actually take effect until after the procedural block, the second assignment does what is intended and actually swaps the two variables -- unlike in a blocking assignment ( = ) or assignments in other languages; f1 still has its original value on the right-hand-side of the second assignment in the block.

Got any verilog Question?

pdf

  • Advertise with us
  • Privacy Policy

Get monthly updates about new articles, cheatsheets, and tricks.

Verification Guide

SystemVerilog Blocking assignment

Blocking assignment.

Blocking assignment statements execute in series order. Blocking assignment blocks the execution of the next statement until the completion of the current assignment execution.

Blocking assignment example

In Below Example, a and b is initialized with value 10 and 15 respectively, after that b is being assigned to a (a value will become 15), and value 20 is assigned to b. After assignment value of a = 15 and b=20.

Simulator Output:

non blocking assignment systemverilog

Blocking assignment example-2

In Below Example, a and b are initialized with value 10 and 15 respectively, after that b is being assigned to a (a value will become 15), and value 20 is assigned to b. After assignment value of a = 15 and b = 20.

❮ Previous Next ❯

...

Blocking and Non-blocking Assignment in Verilog

  • Assignment is only done in procedural block(always ot initial block)
  • Both combintational and sequential circuit can be described.
  • Assignment can only possible to reg type irrespect of circuit type

Let's say we want to describe a 4-bit shift register in Verilog. For this, we are required to declare a 3-bit reg type variable.

The output of shift[0] is the input of shift[1], output of shift[1] is input of shift[2], and all have the same clock. Let's complete the description using both assignment operator.

Non-Blocking Assignment

When we do synthesis, it consider non-blocking assignment separately for generating a netlist. If we see register assignment in below Verilog code, all register are different if we consider non-blocking assignment separately. If you do the synthesis, it will generate 3 registers with three input/output interconnects with a positive edge clock interconnect for all register. Based on the Verilog description, all are connected sequentially because shift[0] is assigned d, shift[1] is assigned shift[0], and shift[2] is assigned shift[1].

Blocking Assignment

If we use blocking assignment and do the syhtheis, the synthesis tool first generate netlist for first blocking assignment and then go for the next blocking assignment. If in next blocking assignment, if previous output of the register is assigned to next, it will generate only a wire of previously assigned register.

In below Verilog code, even though all looks three different assignment but synthesis tool generate netlist for first blocking assigment which is one register, working on positive edge of clock, input d and output shift[0]. Since blocking assignment is used, for next blocking assignment, only wire is generated which is connected to shift[0]. Same is for next statement a wire is generated which is connected to shift[0].

Click like if you found this useful

Add Comment

non blocking assignment systemverilog

This policy contains information about your privacy. By posting, you are declaring that you understand this policy:

  • Your name, rating, website address, town, country, state and comment will be publicly displayed if entered.
  • Your IP address (not displayed)
  • The time/date of your submission (displayed)
  • Administrative purposes, should a need to contact you arise.
  • To inform you of new comments, should you subscribe to receive notifications.
  • A cookie may be set on your computer. This is used to remember your inputs. It will expire by itself.

This policy is subject to change at any time and without notice.

These terms and conditions contain rules about posting comments. By submitting a comment, you are declaring that you agree with these rules:

  • Although the administrator will attempt to moderate comments, it is impossible for every comment to have been moderated at any given time.
  • You acknowledge that all comments express the views and opinions of the original author and not those of the administrator.
  • You agree not to post any material which is knowingly false, obscene, hateful, threatening, harassing or invasive of a person's privacy.
  • The administrator has the right to edit, move or remove any comment for any reason and without notice.

Failure to comply with these rules may result in being banned from submitting further comments.

These terms and conditions are subject to change at any time and without notice.

Creative Commons License

VLSI Verify

Non Blocking Proceduaral assignments

The non-blocking assignment statement starts its execution by evaluating the RHS operand at the beginning of a time slot and schedules its update to the LHS operand at the end of a time slot. Other Verilog statements can be executed between the evaluation of the RHS operand and the update of the LHS operand. As it does not block other Verilog statement assignments, it is called a non-blocking assignment.

A less than or equal to ‘<=’ is used as a symbol for the non-blocking assignment operator.

  • If <= symbol is used in an expression then it is interpreted as a relational operator. 
  • If <= symbol is used in an assignment then it is interpreted as a non blocking operator. 

How race around condition is resolved in a nonblocking assignment?

If a variable is used in LHS of blocking assignment in one procedural block and the same variable is used in RHS of another blocking assignment in another procedural block.

In this example, 

Since procedural blocks (both initial and always) can be executed in any order.

In a non-blocking assignment statement no matter what is the order of execution, both RHS of the assignments (y <= data and data <= y) are evaluated at the beginning of the timeslot and LHS operands are updated at the end of a time slot. Thus, race around condition is avoided as there is no dependency on execution order and the order of execution of these two statements can be said to happen parallelly.

Verilog procedural assignment guidelines

For a beginner in Verilog, blocking and non-blocking assignments may create confusion. If are used blindly, it may create race conditions or incorrect synthesizable design. Hence, it is important to understand how to use them. To achieve synthesized RTL correctly, Verilog coding guidelines for blocking and non-blocking assignments are mentioned below

  • Use non-blocking assignments for modeling flip flops, latches, and sequential logic.
  • Use blocking assignment to implement combinational logic in always block.
  • Use non-blocking assignment to implement sequential logic in always block.
  • Do not mix blocking and non-blocking assignments in single always block i.e. For the implementation of sequential and combination logic in a single ‘always’ block, use non-blocking assignments.
  • Do not assign value to the same variable in the different procedural blocks.
  • Use non-blocking assignments while modeling both combination and sequential logic within the same always block.
  • Avoid using #0 delay in the assignments.

Verilog Tutorials

IMAGES

  1. Non-Blocking Assignment

    non blocking assignment systemverilog

  2. Non-Blocking Socket Communication in SystemVerilog Using DPI-C

    non blocking assignment systemverilog

  3. Swapping the values by blocking and non-blocking assignment in #verilog

    non blocking assignment systemverilog

  4. PPT

    non blocking assignment systemverilog

  5. Blocking vs Non-Blocking Verilog Memory Array Behavior

    non blocking assignment systemverilog

  6. Non Blocking Assignment explanation with example #verilog

    non blocking assignment systemverilog

VIDEO

  1. SoC Episode 5 Monitor and IRQs

  2. Open source design testing and verification with UVM and Verilator (Krzysztof Bieganski=

  3. VERILOG OPERATORS

  4. Non Blocking Assignment explanation with example #verilog

  5. Blocking vs Non blocking Assignment in Verilog #verilog

  6. non blocking-1@verilog@VLSI@FPGA@design verification@RTL design

COMMENTS

  1. Verilog Blocking & Non-Blocking

    Non-blocking assignment allows assignments to be scheduled without blocking the execution of following statements and is specified by a <= symbol. It's interesting to note that the same symbol is used as a relational operator in expressions, and as an assignment operator in the context of a non-blocking assignment.

  2. SystemVerilog NonBlocking assignment

    In the non-blocking assignment, all the assignments will occur at the same time. (during the end of simulation timestamp) Nonblocking assignment example In the below example, a and b are initialized with values 10 and 15 respectively, after that b is being assigned to a (a value will become 15), and value 20 is assigned to b.

  3. Difference between blocking and nonblocking assignment Verilog

    Non-blocking assignment executes in parallel because it describes assignments that all occur at the same time. The result of a statement on the 2nd line will not depend on the results of the statement on the 1st line. Instead, the 2nd line will execute as if the 1st line had not happened yet. Share Cite Follow answered Nov 24, 2013 at 4:21

  4. How to interpret blocking vs non blocking assignments in Verilog

    6 Answers Sorted by: 44 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.

  5. PDF I. Blocking vs. Nonblocking Assignments

    Nonblocking assignment: all assignments deferred until all right-hand sides have been evaluated (end of simulation timestep) always @ (a or b or c) begin x <= y <= z <= | b; ^ b ^ c; & ~c; 1. Evaluate a | 2. Evaluate a^b^c 3. Evaluate b&(~c) but defer assignment of x but defer assignment of y but defer assignment of z end 4. Assign x, y, and

  6. Blocking and Nonblocking Assignments in Verilog

    The concept of Blocking vs. Nonblocking signal assignments is a unique one to hardware description languages. The main reason to use either Blocking or Nonblocking assignments is to generate either combinational or sequential logic. In software, all assignments work one at a time. So for example in the C code below: 1 2 3 LED_on = 0;

  7. PDF Understanding Verilog Blocking and Nonblocking Assignments

    An edge-sensitive intra-assignment timing control permits a special use of the repeat loop. The edge sensitive time control may be repeated several times before the delay is completed. Either the blocking or the non-blocking assignment may be used. always always @(IN) @(IN) OUT OUT <= <= repeat.

  8. verilog Tutorial => Non-blocking assignments

    A non-blocking assignment ( <=) is used for assignment inside edge-sensitive always blocks. Within a block, the new values are not visible until the entire block has been processed. For example:

  9. Blocking or non-blocking statement (= vs. <=)

    Non-blocking assignments were created to help model sequential logic. They help distinguish between the old and new value of a signal. They should be avoided in combinatorial logic as they can create problems with simulation if there are multiple clock domains. It also creates a lot of unnecessary signal rippling. Synthesis tools don't care.

  10. SystemVerilog Blocking assignment

    Blocking assignment blocks the execution of the next statement until the completion of the current assignment execution. Blocking assignment example In Below Example, a and b is initialized with value 10 and 15 respectively, after that b is being assigned to a (a value will become 15), and value 20 is assigned to b.

  11. SystemVerilog Race Condition Challenge Responses

    Race #1 Blocking and non-blocking assignments byte slam; bit dunk; initial begin forever begin @(posedge clk); dunk = ~dunk; slam += dunk; end end always @(posedge clk) basket <= slam + dunk; Race #1 must be the number one most common race condition in Verilog/SystemVerilog. Hardware designers may be more familiar with this race, but ...

  12. Blocking And Nonblocking In Verilog

    Nonblocking Statements: Nonblocking statements allow you to schedule assignments without blocking the procedural flow. You can use the nonblocking procedural statement whenever you want to make several register assignments within the same time step without regard to order or dependence upon each other.

  13. Blocking and Non-blocking Assignment in Verilog

    When working with behavioural modeling in Verilog, there are two types of assigment which is known as blocking and non blocking assigment and both of them there is a operator, '=' operator for blocking assignment and '<=' operator for non blocking assigment.

  14. Task usage using Non-blocking assignment

    But that is before the non-blocking assignment has a chance to update the 'a' argument. So each call to 't1' copies the previous value of 'a' to 'd2'. What you need to do is make 'a' pass by reference instead of by value. Pass by reference also requires that the task have an automatic lifetime. task automatic t1 (input [7:4 ...

  15. Non Blocking Procedural assignments

    Non Blocking Proceduaral assignments. The non-blocking assignment statement starts its execution by evaluating the RHS operand at the beginning of a time slot and schedules its update to the LHS operand at the end of a time slot. Other Verilog statements can be executed between the evaluation of the RHS operand and the update of the LHS operand ...

  16. Is the ++ operator in System Verilog blocking or non-blocking?

    1 Answer Sorted by: 18 According to section 11.4.2 of IEEE Std 1800-2012, it is blocking. SystemVerilog includes the C increment and decrement assignment operators ++i , --i , i++ , and i-- . These do not need parentheses when used in expressions. These increment and decrement assignment operators behave as blocking assignments. Share

  17. Issue with SystemVerilog for loop having non-blocking assignment?

    In this sample code, sum is computed using non-blocking assignments. It was intended to have a value of (1+3+5+6)=15 on the first posedge of clk; which I have observed in original hardware. But in simulation the result was 6 at the posedge of clk (which is abc [3] ). Since the systemverilog simulators schedule the assignments for non-blocking ...

  18. Blocking assignments in always block verilog?

    now I know in Verilog, to make a sequential logic you would almost always have use the non-blocking assignment (<=) in an always block. But does this rule also apply to internal variables? If blocking assignments were to be used for internal variables in an always block would it make it comb or seq logic?