• Docs »
  • 4. Procedural assignments
  • Edit on Bitbucket

4. Procedural assignments ¶

4.1. introduction ¶.

In Chapter 2 , a 2-bit comparator is designed using ‘procedural assignments’. In that chapter, ‘if’ keyword was used in the ‘always’ statement block. This chapter presents some more such keywords which can be used in procedural assignments.

4.2. Combinational circuit and sequential circuit ¶

Digital design can be broadly categorized in two ways i.e. combinational designs and sequential designs . It is very important to understand the differences between these two designs and see the relation between these designs with various elements of Verilog.


Fig. 4.1 Block diagram of ‘combinational’ and ‘sequential’ designs

4.3. Concurrent statements and sequential statements ¶

In Listing 2.3 , we saw that the concurrent statements execute in parallel, i.e. the order of the statement does not matter. Whereas Listing 2.6 shows the example of ‘sequential statements’ where the statements execute one by one. Following are the relationship between ‘statements’ and ‘design-type’,

Remember : (see the words ‘design’, ‘logic’ and ‘statement’ carefully)

4.4. ‘always’ block ¶

All the statements inside the always block execute sequentially. Further, if the module contains more than one always block, then all the always blocks execute in parallel, i.e. always blocks are the concurrent blocks.

Note that, we can write the complete design using sequential programming (similar to C, C++ and Python codes). But that may result in very complex hardware design, or to a design which can not be synthesized at all. The best way of designing is to make small units using ‘continuous assignment statements’ and ‘procedural assignment statements’, and then use the structural modeling style to create the large system.

4.5. Blocking and Non-blocking assignment ¶

There are two kinds of assignments which can be used inside the always block i.e. blocking and non-blocking assignments. The ‘=’ sign is used in blocking assignment; whereas the ‘<=’ is used for non-blocking assignment as shown in Listing 4.1 and Listing 4.2 . Both the listings are exactly same expect the assignment signs at lines 13-14. Due to different in assignment signs, the design generated by these listings are different as shown in Fig. 4.2 and Fig. 4.3 , which are explained below.

Explanation Listing 4.1

In line 10, value of input port ‘x’ is assigned to output ‘z’. Since, the value of ‘z’ is equal to ‘x’, therefore line 11 will be equivalent to ‘z = x + y’; due to this reason, the design is generated as ‘and’ gate with inputs ‘x’ and ‘y’ as shown in Fig. 4.2 . Listing 4.1 Blocking assignment, Fig. 4.2 ¶ 1 2 3 4 5 6 7 8 9 10 11 12 13 // blockAssignment.v module blockAssignment ( input wire x , y , output reg z ); always @( x , y ) begin z = x ; // since z = x z = z & y ; // therefore, z = x + y; end endmodule Fig. 4.2 Blocking assignment, Listing 4.1 Fig. 4.3 Non-blocking assignment, Listing 4.2

Explanation Listing 4.2 :

In non-blocking assignment, updated values inside the block are not used for assignment.} In line 10, value of input port ‘x’ is assigned to the ‘z’. Since updated value inside the block are not used in non-blocking assignment, therefore in line 11, ‘z = z & y;’, the old value of ‘z’ will be used for assignments (instead of z=x); hence a feedback path is used in Fig. 4.3 . Also, ‘x’ has no effect on the design as it is updating ‘z’ inside the block, which will not be used by non-blocking assignment; hence ‘x’ is not connected (i.e. connected to ground) in the design as shown in Fig. 4.3 . Listing 4.2 Non-blocking assignment, Fig. 4.3 ¶ 1 2 3 4 5 6 7 8 9 10 11 12 13 // nonblockAssignment.v module nonblockAssignment ( input wire x , y , output reg z ); always @( x , y ) begin z <= x ; // z_new = x z <= z & y ; // z_new = z_entry + y (not z = z_new + y) end endmodule

The block and non-blocking assignments can not be used together for a signal. For example, the below assignment will generate error as both ‘blocking’ and ‘non-blocking’ assignments are used for ‘z’,

4.6. Guidelines for using ‘always’ block ¶

The general purpose ‘always’ block of Verilog can be misused very easily. And the misuse of this block will result in different ‘simulation’ and ‘synthesis’ results. In this section, the general guidelines are provided for using the ‘always’ block in different conditions.

Further, we can use the specilialized ‘always’ blocks of SystemVerilog to avoid the ambiguities in synthesis and simulation results, which are discussed in Section 10.4 .

Note that, the ‘always’ block is used for ‘synthesis (i.e. with sensitive list)’ as well as ‘simulation (i.e. with and without sensitive list)’, which have different set of semantic rules. If we do not follow the below guidelines in the designs, then simulation and synthesis tools will infer different set of rules, which will result in differences in synthesis and simulation results.

Further, SystemVerilog has specialized ‘always blocks’ for different types of designs (see Section 10.4 ), which can catch the errors when the designs are not created according to below rules.

4.6.1. ‘always’ block for ‘combinational designs’ ¶

Follow the below rules for combinational designs,

4.6.2. ‘always’ block for ‘latched designs’ ¶

Follow the below rules for latched designs,

4.6.3. ‘always’ block for ‘sequential designs’ ¶

Follow the below rules for sequential designs,

4.7. If-else statement ¶

In this section, a 4x1 multiplexed is designed using If-else statement. We already see the working of ‘if’ statement in the Chapter 2 . In lines 11-24 of Listing 4.3 , ‘else if’ and ‘else’ are added to ‘if’ statement. Note that, If-else block can contain multiple ‘else if’ statements between one ‘if’ and one ‘else’ statement. Further, ‘begin - end’ is added in line 12-15 of Listing 4.3 , which is used to define multiple statements inside ‘if’, ‘else if’ or ‘else’ block. Fig. 4.5 shows the waveform generated by Modelsim for Listing 4.3 .

Note that, we are generating the exact designs as the VHDL tutorials, therefore line 22-23 are used. Also, we can remove the line 22-23, and change line 20 with ‘else’, which will also work correctly.


Fig. 4.4 Multiplexer using if statement, Listing 4.3


Fig. 4.5 Waveforms of Listing 4.3 and Listing 4.4

4.8. Case statement ¶

Case statement is shown in lines 11-16 of Listing 4.4 . ‘s’ is used in case statement at line 11; whose value is checked using ‘when’ keyword at lines 12 and 13 etc. The value of the output y depends on the value of ‘s’ e.g. if ‘s’ is ‘1’, then line 12 will be true, hence value of ‘i1’ will be assigned to ‘y’. Note that, we can use ‘integer’ notation (line 12) as well as ‘binary’ notation (line 13) in ‘case’ and ‘if’ statements. Design generated by Listing 4.4 is shown in Fig. 4.6 .


Fig. 4.6 Multiplexer using case statement, Listing 4.4

We need not to define all the possible cases in the ‘case-statement’, the ‘default’ keyword can be used to provide the output for undefined-cases as shown in Listing 4.5 . Here, only two cases are defined i.e. 7 and 3; for the rest of the cases, the default value (i.e. i2) will be sent to the output.

4.9. Problem with Loops ¶

Verilog provides two loop statements i.e. ‘for’ loop and ‘while’ loop’. These loops are very different from software loops. Suppose ‘for i = 1 to N’ is a loop’, then, in software ‘i’ will be assigned one value at time i.e. first i=1, then next cycle i=2 and so on. Whereas in Verilog, N logics will be implement for this loop, which will execute in parallel. Also, in software, ‘N’ cycles are required to complete the loop, whereas in Verilog the loop will execute in one cycle.

As loops implement the design-units multiple times, therefore design may become large and sometimes can not be synthesized as well. If we do not want to execute everything in one cycle (which is almost always the case), then loops can be replaced by ‘case’ statements and ‘conditional’ statements as shown in section Section 4.10 . Further, due to these reasons, we do not use loops in the design, and hence these are not discussed in the tutorial.

4.10. Loop using ‘if’ statement ¶

In Listing 4.6 , a loop is created using ‘if’ statement, which counts the number upto input ‘x’.

Explanation Listing 4.6

In the listing, two ‘always’ blocks are used i.e. at lines 20 and 33. The process at line 20 checks whether the signal ‘count’ value is ‘less or equal’ to input x (line 22), and sets the currentState to ‘continueState’; otherwise if count is greater than the input x, then currentState is set to ‘stopState’. Then next ‘always’ statement (line 33), increase the ‘count’ by 1, if currentState is ‘continueState’; otherwise count is set to 0 for stopState. Finally count is displayed at the output through line 41. In this way, we can implement the loops using the ‘always’ statements. Fig. 4.7 shows the loop generated by the listing with parameter N=1. Further, Fig. 4.8 shows the count-waveforms generated by the listing with parameter N = 3.

Sensitivity list is still not correct in the Listing 4.6 e.g. we do not put the ‘x’ in the sensitive list at Line 20 which is used inside the ‘always’ block. Further, the ‘clk’ is unnecessarily used at Line 33.

Although the results are correct, but such practice leads to undetectable errors in large designs. We will see the correct style of coding in Chapter 7 .


Fig. 4.7 Loop using ‘if’ statement, Listing 4.6 with N = 1


Fig. 4.8 Loop using ‘if’ statement, Listing 4.6 with N = 3

Sensitivity list of the always block should be implemented carefully. For example, if we add ‘count’ in the sensitivity list at line 33 of Listing Listing 4.6 , then the always block will execute infinite times. This will occur because the always block execute whenever there is any event in the signals in the sensitivity list; therefore any change in ‘count’ will execute the block, and then this block will change the ‘count’ value through line 36. Since ‘count’ value is changed, therefore always block will execute again, and the loop will never exit.

Another problem is that, above error can not be detected during simulation phase, i.e. simulation will show the correct results. Such errors are very difficult to find in Verilog. Further, such errors can be identified in VHDL code, as shown in VHDL tutorials. To avoid such errors in Verilog, please follow the guidelines for using the ‘always’ block as described in Section 4.6 .

4.11. Conclusion ¶

In this chapter, various statements for procedural assignments are discussed. Problem with loops are discussed and finally loop is implemented using ‘if’ statement. Lastly, it is shown that, Verilog designs can have differences in simulation results and implementation results.


Slick on Silicon

Verilog: Continuous & Procedural Assignments

types of assignment in verilog

Continuous Assignment

Continuous assignment is used to drive a value on to a net in dataflow modeling. The net can be a vector or scalar, indexed part select, constant bit or part select of a vector. Concatenation is also supported with scalar vector types.

Regular & Implicit Assignment

Regular continuous assignment means, the declaration of a net and its continuous assignments are done in two different statements. But in implicit assignment, continuous assignment can be done on a net when it is declared itself. In the below example, `valid` is declared as wire during the assignment. If signal name is used to the left of the continuous assignment, an implicit net declaration will be inferred. In the below code `dout` is not declared as net, but it is inferred during assignment.

Procedural Assignment

We have already seen that continuous assignment updates net, but procedural assignment update values of reg, real, integer or time variable. The constant part select, indexed part select and bit select are possible for vector reg.

3 comments on “ Verilog: Continuous & Procedural Assignments ”

' src=

Excellent blog

' src=

Clearly explained.. Thanks

' src=

sir what’s your company/industry name.

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.

Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

<= Assignment Operator in Verilog

What does the <= do in Verilog?

For example:

nick_g's user avatar

6 Answers 6

"<=" in Verilog is called non-blocking assignment which brings a whole lot of difference than "=" which is called as blocking assignment because of scheduling events in any vendor based simulators.

It is Recommended to use non-blocking assignment for sequential logic and blocking assignment for combinational logic, only then it infers correct hardware logic during synthesis.

Non-blocking statements in sequential block will infer flip flop in actual hardware.

Always remember do not mix blocking and non-blocking in any sequential or combinational block.

During scheduling process of simulator:

There are four regions and order of execution of commands as follows

Using of blocking assignment "=" for two variable at the same time slot causes race condition

eg: Verilog code with race condition,

In order to avoid race condition use non-blocking statement "<="

When this block is executed, there will be two events added to the non blocking assign update queue. Hence, it does the updation of BCD1 from BCD0 at the end of the time step.

Using Non-blocking "<=" assignment in continuous assignment statement is not allowed according to verilog LRM and will result in compilation error.

Only use NBA in procedural assignment statements,

Paul Floyd's user avatar

This is called a 'non-blocking' assignment. The non-blocking assignment allows designers to describe a state-machine update without needing to declare and use temporary storage variables.

For example, in this code, when you're using a non-blocking assignment, its action won't be registered until the next clock cycle. This means that the order of the assignments is irrelevant and will produce the same result.

The other assignment operator, '=', is referred to as a blocking assignment. When '=' assignment is used, for the purposes of logic, the target variable is updated immediately.

The understand this more deeply, please look at this example (from Wikipedia):

In this example, flop1 <= flop2 and flop2 <= flop1 would swap the values of these two reg s. But if we used blocking assignment, = , this wouldn't happen and the behavior would be wrong.

Sadjad's user avatar

Since people have already explained the blocking/non blocking situation, I'll just add this here to help with understanding. " <= " replaces the word "gets" as you read code

For example :

.... //Verilog code here

A<=B //read it as A gets B

When does A get B? In the given time slot, think of everything in hardware happening in time slots, like a specific sampled event, driven by clock. If the "<=" operator is used in a module with a clock that operates every 5ns, imagine A getting B at the end of that time slot, after every other "blocking" assignments have resolved and at the same time as other non blocking assignments.

I know its confusing, it gets better as you use and mess up bunch of designs and learn how it works that way.

Digitalzombie's user avatar

"<=" is a non-blocking assignment operator in verilog."=" is a blocking assignment operator.

Consider the following code..

The values of a and b are being exchanged using two different always blocks.. Using "=" here caused a race-around condition. ie. both the variables a and b are being changes at the same time.. Using "<=" will avoid the race-around.

Hope i helped too..

badari259's user avatar

<= is a non blocking assignment. The <= statements execute parallely. Think of a pipelined architecture, where we come across using such assignments.

A small exammple:

// initialise a, b, c with 1, 2 and 3 respectively. initial begin a <= 1 b <= 2 c <= 3 end

[email protected](clock.posedge) begin a <= b b <= c c <= a end

After the first posedge clock: a = 2, b = 3, c = 1

After the second posedge clock: a = 3, b = 1, c = 2

After third posedge clock: a = 1, b = 2, c = 3

vikram9866's user avatar

As most told, it is a "Non Blocking <=" assignment widely used for Sequential logic design because it can emulate it best.

Here is why :

Mostly involving a delay(here posedge clock) it is something like it schedules the evaluation of the RHS to LHS after the mentioned delay and moves on to the next statement(emulating sequential) in flow unlike "Blocking = " which will actually delay the execution of the next statement in line with the mentioned delay (emulating combinational)

ChrisF's user avatar

Your Answer

Sign up or log in, post as a guest.

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service , privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged verilog or ask your own question .

Hot Network Questions

types of assignment in verilog

Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy .



Vrit Raval

Sep 4, 2019


There are two types of assignments in veriolg

Continuous Assignment

Procedural assignment.

A procedural assignment updates the value of register data types.


Procedural assignments are used for updating register data types and memory data types.

The expression in a blocking procedural assignment is evaluated and assigned when the statement is encountered. In a begin-end sequential statement group, execution of the next statement is blocked until the assignment is complete.

In a non-blocking procedural assignment, the expression is evaluated when the statement is encountered, and assignment is postponed until the end of the time-step. In a begin-end sequential statement group, execution of the next statement is not blocked and may be evaluated before the assignment is complete. A group of statements with a non-blocking assignment has similar functionality as a group of statements within a fork-join block.

The left-hand side of a procedural assignment should be one of the following:

When the right-hand side evaluates to a fewer bits than the left-hand side, the assignment to a reg does not sign-extend.

The evaluation of the assignment is delayed by the delay when the delay is specified before the register name. When the delay is specified before the expression, the expression is evaluated when the statement is encountered, and assigned in the time-step specified by the delay.

A continuous assignment drives a value into a net.

Continuous assignments model combinational logic. Each time the expression changes on the right-hand side, the right-hand side is re-evaluated, and the result is assigned to the net on the left-hand side.

The implicit continuous assignment combines the net declaration (see Net data type) and continuous assignment into one statement. The explicit assignment require two statements: one to declare the net (see Net data type), and one to continuously assign a value to it.

Continuous assignments are not the same as procedural continuous assignments. Continuous assignments are declared outside of procedural blocks. They automatically become active at time zero, and are evaluated concurrently with procedural blocks, module instances, and primitive instances.



About Help Terms Privacy

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store

Living on and off in the world of gates and flipflops!! A VLSI enthusiast!

Text to speech

Verilog Data Types

The primary intent of data-types in the Verilog language is to represent data storage elements like bits in a flip-flop and transmission elements like wires that connect between logic gates and sequential structures.

What values do variables hold ?

Almost all data-types can only have one of the four different values as given below except for real and event data types.

The following image shows how these values are represented in timing diagrams and simulation waveforms. Most simulators use this convention where red stands for X and orange in the middle stands for high-impedance or Z .

What does the verilog value-set imply ?

Since Verilog is essentially used to describe hardware elements like flip-flops and combinational logic like NAND and NOR, it has to model the value system found in hardware. A logic one would represent the voltage supply V dd which can range anywhere between 0.8V to more than 3V based on the fabrication technology node. A logic zero would represent ground and hence a value of 0V.

X or x means that the value is simply unknown at the time, and could be either 0 or 1. This is quite different from the way X is treated in boolean logic, where it means "don't care".

As with any incomplete electric circuit, the wire that is not connected to anything will have a high-impedance at that node and is represented by Z or z . Even in verilog, any unconnected wire will result in a high impedance.

Nets and Variables

Nets and variables are the two main groups of data types which represent different hardware structures and differ in the way they are assigned and retain values.

Nets are used to connect between hardware entities like logic gates and hence do not store any value on its own. In the image shown below, a net called net_11 is used to connect between the output of the AND gate to the first input of the flip-flop called data_0 . In a similar way, the two inputs of the AND gate are connected to nets net_45 and net_67 .

There are different types of nets each with different characteristics, but the most popular and widely used net in digital designs is of type wire . A wire is a Verilog data-type used to connect elements and to connect nets that are driven by a single gate or continuous assignment. The wire is similar to the electrical wire that is used to connect two components on a breadboard.

When there is a requirement for mulitple nets, they can be bunched together to form a single wire . In the image shown below, we have a 4-bit wire that can send 4 separate values on each one of the wires. Such entities with a width more than 1 are called vectors as we shall see in the next article.

It is illegal to redeclare a name already declared by a net, parameter or variable as shown in the code below.

A variable on the other hand is an abstraction of a data storage element and can hold values. A flip-flop is a good example of a storage element.

Verilog data-type reg can be used to model hardware registers since it can hold values between assignments. Note that a reg need not always represent a flip-flop because it can also be used to represent combinational logic.

In the image shown on the left, we have a flip-flop that can store 1 bit and the flip-flop on the right can store 4-bits.

Other data-types

An integer is a general purpose variable of 32-bits wide that can be used for other purposes while modeling hardware and stores integer values.

A time variable is unsigned, 64-bits wide and can be used to store simulation time quantities for debugging purposes. A realtime variable simply stores time as a floating point quantity.

A real variable can store floating point values and can be assigned the same way as integer and reg .

Verilog Strings

Strings are stored in reg , and the width of the reg variable has to be large enough to hold the string. Each character in a string represents an ASCII value and requires 1 byte. If the size of the variable is smaller than the string, then Verilog truncates the leftmost bits of the string. If the size of the variable is larger than the string, then Verilog adds zeros to the left of the string.

Here is a full example showing how the three variables given above can be simulated.

Note that str1 has the right size to store all 11 bytes of the string "Hello World" and hence the whole string gets printed. However str2 can store only 5 bytes and hence the upper 6 bytes get truncated and end up with storing only "World". The third variable str3 is larger than 11 bytes and pads empty spaces to the left and hence the value stored in it becomes "        Hello World".

Javatpoint Logo

Verilog Tutorial


Help Others, Please Share


Learn Latest Tutorials

Splunk tutorial


Tumblr tutorial

Reinforcement Learning

R Programming tutorial

R Programming

RxJS tutorial

React Native

Python Design Patterns

Python Design Patterns

Python Pillow tutorial

Python Pillow

Python Turtle tutorial

Python Turtle

Keras tutorial



Verbal Ability

Interview Questions

Interview Questions

Company Interview Questions

Company Questions

Trending Technologies

Artificial Intelligence

Artificial Intelligence

AWS Tutorial

Cloud Computing

Hadoop tutorial

Data Science

Angular 7 Tutorial

Machine Learning

DevOps Tutorial

B.Tech / MCA

DBMS tutorial

Data Structures

DAA tutorial

Operating System

Computer Network tutorial

Computer Network

Compiler Design tutorial

Compiler Design

Computer Organization and Architecture

Computer Organization

Discrete Mathematics Tutorial

Discrete Mathematics

Ethical Hacking

Ethical Hacking

Computer Graphics Tutorial

Computer Graphics

Software Engineering

Software Engineering

html tutorial

Web Technology

Cyber Security tutorial

Cyber Security

Automata Tutorial

C Programming

C++ tutorial

Control System

Data Mining Tutorial

Data Mining

Data Warehouse Tutorial

Data Warehouse

Javatpoint Services

JavaTpoint offers too many high quality services. Mail us on [email protected] , to get more information about given services.

Training For College Campus

JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected] Duration: 1 week to 2 week

RSS Feed

09 Sep 2021

In Verilog, there are various ways for assignment, due to the concurrent nature of the Verilog code. Also, to represent the combinational and sequential digital circuits, Verilog provides different ways for assignment which helps to model the hardware accurately.

As we know, Verilog has net and reg data types, which represent a wire and flip flop respectively. From hardware point of view, wires are driven continuously once the circuit is switched on, thus for every point of time wire will take the value which is fed into as it cannot retain any previous value. To represent this behaviour, Verilog provides continuous assignment. This will assign certain value to the wire at every time step.

Similarly, flip flops, are not driven continuously, rather it is driven at some clock edge or any other event, as flip flops retain the value until it is changed. This is the expected behaviour in sequential circuits. To represent this behaviour, Verilog provides procedural assignment, in which the assignment will be done only if certain event is triggered. Let’s see these assignments in detail.

Continuous Assignment

As discussed earlier this assignment is generally used for net data types. assign keyword is used for continuous assignment and is used directly inside the module, i.e., procedural blocks are not required for this type of assignment.

Procedural Assignment

Procedural assignments are used with flip flops, i.e., for sequential circuits. Thus, it can be used to drive only variables and not any net data type. Also, this type of assignment can only be used inside a procedural block, i.e., initial or always .

Procedural assignment can further be divided into 2 types:

Blocking Assignment

This type of assignment is the same as we see in all the programming language. As the name suggests, program flow will be blocked until the assignment is complete. This assignment is done using the help of = operator, which is also known as blocking assignment operator. Blocking assignment is executed in the Active region of the event semantics . As we know, the active region does not guarantee the order of execution, thus this type of assignment is prone to race conditions as discussed in previous article.

Non-blocking Assignment

This type of assignment, as name suggests, does not block the flow of program. The RHS of the assignment operation is calculated but it is not assigned to LHS. All the non-blocking assignments are executed at the end of the time-step in NBA region of event semantics and the LHS gets assigned with the calculated RHS. NBAs are done using <= operator which is also known as non-blocking assignment operator. As this assignment is done in NBA region, it helps prevent race around condition. We will see how this prevents race around condition with example later in this article.

Procedural Continuous Assignment

This is a continuous assignment which is used inside the procedural blocks. This is mainly used when we want to override the value of a variable or net. These types of assignments can be achieved using

Assign deassign keywords

These are used to override the value of a variable until the variable is de-assigned using deassign keyword. After de-assignment, the value of the variable will remain the same until it is re-assigned using procedural or procedural continuous assignment. These can be used only used when LHS is a variable or concatenation of variable.

In below example, the value of a is continuously incremented in the first initial block. In the second initial block, at t=17 , the value of a is overridden using assign keyword, and thus the value of a is not getting incremented. Once deassign is used at t=27 , the value of a starts getting incremented.

The value of a is not getting printed once the value of a is overridden, as $monitor prints only when the value of the variable changes. As assign does not let the value change, thus value of a is not getting printed even after a is incremented.

Force release keyword

These are same as that of assign-deassign statement but it can be used for both nets and variables. The LHS can be a bit-select, part-select of net but cannot be an array or a bit or part select of variables. These will override all other assignments until released.

In below example, b is continuously assigned ~a , i.e., inverse of a. In first initial block value of a is incremented and the value of b also changes. In second initial block, at t=15 value of a is overridden using force keyword. Value of b changes with response to a . At t=25 value of b[2:1] is overridden with force keyword, and thus now only the first and last bit of b can change. At t=35 variable a is released, and value of a can be changed, but net b is still not released, so only the first and the last bit of b changes with change in a . At t=45 net b is also released and now all bits of b is changed with change in a .

Prevention of race around condition

Race around condition, which was discussed in earlier article , can be prevented by using a non-blocking assignment. As we know in non-blocking assignment, the LHS is assigned in the non-blocking region of event semantics, which comes after the active regions, thus the value is determinate as all the calculations have been already done. Let’s understand this with an example.

In the 1st code, at the positive edge of clk , variable a is assigned a value whereas at the same time b is reading of value of a . As order of execution in active region is not guaranteed in Verilog, thus it can lead to a race around condition.

Whereas in 2nd code, as non-blocking assignment is used, thus 1 will not be assigned immediately to a . Now when, b access the variable a it will always read the previous value stored, in this case 0 . Thus, b will be assigned with 0 and a will be assigned with 1 at the send of the time step. Also note that for b to attain the value of a , it takes 2 cycles, thus at t=30, b = 1

1st code - having race around condition

2nd code - solution for race condition.


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.

Behavioral Modeling Style in Verilog

What is behavioral modeling, continuous assignment statements, procedural assignment statements, blocking statements , non-blocking statements.

Non-blocking assignments are executed in parallel. Since the execution of the next statement is not blocked due to the execution of the current statement, they are called non-blocking statements. Assignments are made with the “<=” symbol.

Structured procedural statement

Initial statement.

where a procedural_statement is one of the statements we are going to discuss in this post. The timing control will specify a delay time. A detailed explanation of timing control is discussed further.

Always Statement

Procedural continuous statement, assign – deassign, force – release.

The keywords  force  and  release  can be used for nets, registers, bit- or part select of a net (not register), or a concatenation.

Block statement

Sequential block, parallel block.

Assume that the simulation time for the above example is 10-time units. Now the first statement will be executed after 10 + 19 = 29-time units, the second statement after 20-time units, and the last statement will take 30-time units. Therefore, after 30-time units, the execution control will be transferred out of the block.

Timing control

Delay control, event control.

In this instance, the statement sum=0 will execute once the value of s variable is greater than 22.

Conditional statement

If statement, if-else statement, nested if-else-if, case statement.

The case statement is a multi-way deciding statement which first matches a number of possibilities and then transfers a single matched input to the output. This is most useful in decoding various operations inside a processor.

A for loop statement repeats the execution of the procedural statements for a certain number of times till the condition is true. The initial_assignmen t statement specifies the initial value of the loop or the index variable. The condition  specifies the condition for which the loop will keep executing, and the step_assignment mostly directs the variable to be incremented or decremented.

Repeat loop

Forever loop.

This was an in-depth glossing over of the main elements of the behavioral modeling style in Verilog. As always, if there are any doubts, let us know in the comments section. Make sure to apply these concepts in your programming practice routines. Check out the various examples in the sidebar for behavioral modeling for reference.

Related courses to Behavioral Modeling Style in Verilog

CMOS - IC Design Course

Vhdl course, digital electronics course, leave a reply cancel reply.

Related Articles

Verilog Data Types

The data storage and transmission elements found in digital hardware are represented using a set of Verilog Hardware Description Language (HDL) data types. The purpose of Verilog HDL is to design digital hardware. 

Data types in Verilog are divided into NETS and Registers . These data types differ in the way that they are assigned and hold values, and also they represent different hardware structures. 

The Verilog HDL value set consists of four basic values:

Notes –

Reference: DIGITAL ELECTRONICS – Atul P.Godse, Mrs. Deepali A. Godse

Please Login to comment...

New Course Launch!

Improve your Coding Skills with Practice

Start your coding journey now.


  1. Verilog Interview Questions Part 3

    types of assignment in verilog

  2. PPT

    types of assignment in verilog

  3. Programmable Logic/Verilog Data Types

    types of assignment in verilog

  4. Verilog Construction

    types of assignment in verilog

  5. Online Verilog Assignment Help Service

    types of assignment in verilog

  6. 😍 Verilog assignment. Conditional Operator. 2019-02-03

    types of assignment in verilog


  1. Teacher's feedback, types and importance assignment

  2. Water And Waste Water Treatment #Assignment No.6 Answers #Week 6 Answers #NPTEL 2023

  3. Water And Waste Water Treatment #Assignment No.5 Answers #Week 5 Answers #NPTEL 2023

  4. Lecture 3 Types Assignment problems

  5. Verilog Session-2

  6. RTL based Verification || functional verification ||Types of testbench ||Stimulus,driver,DUT,monitor


  1. Verilog Assignments

    Verilog Assignments Placing values onto nets and variables are called assignments. There are three basic forms: Procedural Continuous Procedural continuous Legal LHS values An assignment has two parts - right-hand side (RHS) and left-hand side (LHS) with an equal symbol (=) or a less than-equal symbol (<=) in between.

  2. Verilog assign statement

    Verilog also allows an assignment to be done when the net is declared and is called implicit assignment. wire [1:0] a; assign a = x & y; wire [1:0] a = x & y; Combinational Logic Design Consider the following digital circuit made from combinational gates and the corresponding Verilog code.

  3. PDF Intro to Verilog

    use Verilog's operators and continuous assignment statements: Conceptually assign's are evaluated continuously, so whenever a value used in the RHS changes, the RHS is re-evaluated and the value of the wire/bus specified on the LHS is updated. This type of execution model is called "dataflow" since evaluations

  4. PDF I. Blocking vs. Nonblocking Assignments

    Evaluate b&(~c) but defer assignment of z 1. Evaluate a | b, assign result tox x 2. Evaluate a^b^c, assign result to y 3. Evaluate b&(~c), assign result to zz I. Blocking vs. Nonblocking Assignments • Verilog supports two types of assignments within always blocks, with subtly different behaviors. • Blocking assignment: evaluation and ...

  5. 4. Procedural assignments

    There are two kinds of assignments which can be used inside the always block i.e. blocking and non-blocking assignments. The '=' sign is used in blocking assignment; whereas the '<=' is used for non-blocking assignment as shown in Listing 4.1 and Listing 4.2. Both the listings are exactly same expect the assignment signs at lines 13-14.

  6. Verilog: Continuous & Procedural Assignments

    There are two types of procedural assignments called blocking and non-blocking. Blocking assignment, as the name says, gets executed in the order statements are specified. The "=" is the symbol used for blocking assignment representation. Non-blocking assignment allows scheduling of assignments. It will not block the execution.

  7. <= Assignment Operator in Verilog

    1) Active region --Blocking assignments --Evaluation of RHS of non-blocking assignments (NBA) --Continuous assignment --$display command --Evaluate input and output of primitives 2) Inactive region --#0 blocking assignments 3) NBA (non-blocking assignment update) --update LHS of non-blocking assignments (NBA) 4) Postponed --$monitor command …

  8. ASSIGNMENTS IN VERILOG. There are two types of assignments in…

    There are two types of assignments in… | by Vrit Raval | VERILOG NOVICE TO WIZARD | Medium Sign up 500 Apologies, but something went wrong on our end. Refresh the page, check Medium 's site...

  9. Verilog Data Types

    There are different types of nets each with different characteristics, but the most popular and widely used net in digital designs is of type wire. A wire is a Verilog data-type used to connect elements and to connect nets that are driven by a single gate or continuous assignment.

  10. PDF Verilog Synthesis

    Procedural Assignments • Verilog has two types of assignments within always blocks: • Blocking procedural assignment "=" - RHS is executed and assignment is completed before the next statement is executed; e.g., Assume A holds the value 1 … A=2; B=A; A is left with 2, B with 2. • Non-blocking procedural assignment "<="

  11. Verilog

    Verilog, standardized as IEEE 1364, is a hardware description language (HDL) used to model electronic systems. ... There are two types of assignment operators; a blocking assignment (=), and a non-blocking (<=) assignment.

  12. Verilog Assignments

    Verilog Assignments Placing values onto variables and nets are called assignments. There are three necessary forms: Procedural Continuous Procedural continuous Legal LHS values An assignment has two parts, right-hand side (RHS) and left-hand side (LHS) with an equal symbol (=) or a less than-equal symbol (<=) in between.

  13. PDF L5: Simple Sequential Circuits and Verilog

    Blocking vs. Nonblocking Assignments Verilog supports two types of assignments within alwaysblocks, 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)

  14. Verilog Assign Statement

    Implicit Continuous Assignment When an assign statement is used to assign the given net with some value, it is called an explicit assignment If an assignment to be done during the net is declared, it is called an implicit assignment. wire [1:0] a; assign a = x & y; // Explicit assignment wire [1:0] a = x & y; // Implicit assignment

  15. Verilog Assignments

    Procedural assignment can further be divided into 2 types: Blocking Assignment Non-blocking Assignments Blocking Assignment This type of assignment is the same as we see in all the programming language. As the name suggests, program flow will be blocked until the assignment is complete.

  16. Blocking and Nonblocking Assignments in Verilog

    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 1 2 3 4 5 6

  17. Behavioral Modeling Style in Verilog

    There are two kinds of procedural continuous assignments. Assign - deassign: these assign to registers. Force - release: these primarily assign to nets, although they can also be used for registers. Assign - deassign The keywords assign and deassign can be used for registers or a concatenation of registers only.

  18. Verilog Data Types

    The Verilog HDL value set consists of four basic values: NETS - The nets variables represent the physical connection between structural entities. These variables do not store values (except trireg); they have the value of their drivers which changes continuously by the driving circuit.