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.

...

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

blocking assignment

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.

Comments (1)

Avatar

hey in blocking assignment do we get shift in data i dont think so . we get all values same and equal to d.

Please do not focus on the module name; focus on how the netlist is generated after the synthesis.

Creative Commons License

404 Not found

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:

blocking assignment

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 ❯

Synthesis and Functioning of Blocking and Non-Blocking Assignments.

Here are some examples on blocking and non-blocking assignments in Verilog , that can be really useful for the budding design Engineers. First let us discuss the features of these assignments.

  • They are procedural assignments always used in a procedural block like initial or always .
  • In BA (Blocking assignment) RHS of the assignment is assigned immediately to the LHS in the active region of the scheduler, that is to understand we can say the assignment is immediate and it does not wait for the procedural block to end. While in NBA (Non-Blocking Assignments) the RHS is calculated first, then it is assigned to the LHS much later in the scheduler, that is to understand after the completion of procedural block (initial or always). Other wise we can say that they get executed in the NBA part of the scheduler which is second last in the sequence after Active and Inactive. .
  • In BA, assignments are done in the sequence in which they are written, In NBA all the RHS are calculated and stored in the temporary memory of the compiler and then are assigned to the LHS, at the same time, that is there is no set order of assigning, it depends on the compiler.

The following example illustrates the Blocking Assignment

BA

Example (a) Synthesis view of four bit shift reg.

4bit_shftreg

but if changed into Blocking Assignments.

collapse_sr

Example (b) Example for scheduling.

clock_toggle

but if changed assignments to Blocking Assignments

clk_not_tgle

P.S Whenever you want to implement a fast event independent circuit like combinational circuits where the present value gets updated immediately, Use blocking assignments and whenever there are assignments that to be made together after an event use NBA, usually in sequential circuits.

Spread the Word

  • Click to share on Facebook (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Pinterest (Opens in new window)
  • Click to share on Tumblr (Opens in new window)
  • Click to share on Pocket (Opens in new window)
  • Click to share on Reddit (Opens in new window)
  • Click to email a link to a friend (Opens in new window)
  • Click to print (Opens in new window)

Related posts:

  • Blocking (immediate) and Non-Blocking (deferred) Assignments in Verilog
  • Case and Conditional Statements Synthesis CAUTION !!!
  • Synopsys – Interview Questions – based on Synthesis and Simulation
  • Synthesis in VLSI

Post navigation

Leave a reply cancel reply.

Your email address will not be published. Required fields are marked *

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

Notify me of follow-up comments by email.

Notify me of new posts by email.

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

COMMENTS

  1. Verilog Blocking & Non-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. PDF I. Blocking vs. Nonblocking Assignments

    I. Blocking vs. Nonblocking Assignments • 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 timestep)

  3. Blocking and Nonblocking Assignments in Verilog

    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 ...

  4. Difference between blocking and nonblocking assignment Verilog

    A blocking assignment takes affect immediately it is processed. A nonblocking assignment takes place at the end of processing the current "time delta". always blocks can be used to model either combinatorial or sequential logic (systemverilog has always_comb and always_ff to make this explicit). When modeling combinatorial logic it's usually ...

  5. Blocking and Non-blocking Assignment in Verilog

    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.At short, blocking assignment executes one by one sequentially and non-blocking assignemnt ...

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

    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.

  7. PDF Advanced Verilog

    Blocking vs Non-Blocking Cont • Non-blocking assignments literally do not blockthe execution of the next statements. The right side of all statements are determined first, then the left sides are assigned together. - Consequently, non-blocking assignments result in simultaneous or parallel statement execution. For example: assume a = b = 0 ...

  8. Understanding the Differences Between Blocking and Non-Blocking

    This episode provides a comprehensive analysis of the key differences between blocking and non-blocking assignments in Verilog. The host begins by introducin...

  9. PDF Blocking and Non-blocking Assignments in Explicit and Implicit Style

    two blocking assignments: one that evaluates the right-hand side and saves the result in a temporary variable, and the other that later stores the temporary value into the variable in question [1]. It is also true that every blocking assignment can be translated into a series of non-blocking assignments, but

  10. Blocking (immediate) and Non-Blocking (deferred) Assignments in Verilog

    Blocking assignments. Blocking assignments (=) are done sequentially in the order the statements are written. A second assignment is not started until the preceding one is complete. i.e, it blocks all the further execution before it itself gets executed. Example: input a, // Assume a=1 initialized at time '0'. input b, // Assume b=0 initialized ...

  11. Blocking Assignments

    The blocking assignment statements are executed sequentially by evaluating the RHS operand and finishes the assignment to LHS operand without any interruption from another Verilog statement. Hence, it blocks other assignments until the current assignment completes and is named as "blocking assignment". ...

  12. Blocking And Nonblocking In Verilog

    Blocking And Nonblocking In Verilog. Blocking Statements: A blocking statement must be executed before the execution of the statements that follow it in a sequential block. In the example below the first time statement to get executed is a = b followed by. Nonblocking Statements: Nonblocking statements allow you to schedule assignments without ...

  13. PDF Nonblocking Assignments in Verilog Synthesis, Coding Styles That ...

    3.0 Blocking assignments The blocking assignment operator is an equal sign ("="). A blocking assignment gets its name because a blocking assignment must evaluate the RHS arguments and complete the assignment without interruption from any other Verilog statement. The assignment is said to "block" other assignments until the current assignment ...

  14. Mastering Verilog: Part 5- Understanding Blocking and Non ...

    The significance of blocking and non-blocking assignments in Verilog coding cannot be overstated. These elements serve as the foundation for precise and effective digital circuit design, offering ...

  15. Blocking and Nonblocking Assignments in Verilog

    The Blocking assignment immediately takes this value in the right-hand-side and assignment computer to the left reach 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 to want to build combinational logic use an always block for ...

  16. 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. After assignment value of a ...

  17. 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.

  18. Blocking and Non Blocking Assignments in Verilog

    This video help to learn Blocking and Non Blocking Assignment using Verilog HDL.#Learnthought #veriloghdl #verilog #vlsidesign #veriloglabprograms #verilogla...

  19. Synthesis and Functioning of Blocking and Non-Blocking Assignments

    Here are some examples on blocking and non-blocking assignments in Verilog, that can be really useful for the budding design Engineers.First let us discuss the features of these assignments. They are procedural assignments always used in a procedural block like initial or always.; In BA (Blocking assignment) RHS of the assignment is assigned immediately to the LHS in the active region of the ...

  20. Blocking assignments in always block verilog?

    In you case using 'blocking' for the 'counter' will cause mismatch in synthesis behavior. Synthesis will create flops for both q and count. However, in your case with blocking assignment the count will be decremented immediately after it is being assigned the prescaled value, whether after synthesis, it will happen next cycle only.

  21. 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 ...