Behavioural description and its translation into structural description in verilog

Welcome back readers :)

So far, we discussed modules and ports. Now we will see how Verilog helps in writing code in behavioural description and translates it to structural description i.e., the actual circuit.

Verilog allows us to describe the abstract behaviour of our module and the synthesis tool synthesizes the behaviour into actual hardware. There are two types of behavioural blocks in Verilog, they are initial and always.

  • Behaviour declared by initialΒ is known as single-pass behaviourΒ where, which means that all the statements inside this block will execute once and once all the statements are executed then this block will terminate. On the other hand, behaviour described by alwaysΒ block is known as cyclic behaviourΒ and it will always execute when the event control expression is true.

  • Before moving ahead let’s have a look at the different ways of assignment. There are two types of assignment in Verilog, they are continuous assignmentΒ and procedural assignment.

  • For β€œcontinuous assignment” the syntax is as follows:

assignΒ {Y} = {expression};

Β  Β  Here Y should be of β€œnet” data type, β€œnet” data types are declared explicitly by syntax wire.

Β  Β  Below is an example of 3 input AND gate using continuous assignment

moduleΒ AND3 (Y,A,B,C);

Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β inputΒ A,B,C;

Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β outputΒ Y;

Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β wireΒ Y; Β  //net declaration

Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β assignΒ Y =Β (A &Β B &Β C);

endmodule

Β  Β  Let’s see one more example of a 2:1 multiplexer

moduleΒ MUX2to1 (Y,I_0,I_1,S);

Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β inputΒ I_0,I_1,S;

Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β outputΒ Y;

Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β wireΒ Y; Β  //net declaration

Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β assignΒ Y =Β (S ?Β I_1 :Β I_0);

endmodule

  • "Procedural assignments” are the assignments that are done inside the behavioural blocks (initial and always). Here the variable to the left (variable which is assigned) must be of typeΒ β€œreg” data type.

Β  Β 

Β  Further there are two different kinds of procedural assignments, they are blockingΒ andΒ non-blockingΒ assignments.

  • Blocking assignments: Operator used for blocking assignment is (=) {equal to}. In case of blocking assignment, the statements are executed sequentially in the order they are written.
  • Non-blocking assignments: Operator used for non-blocking assignment is (<=) {less than equal to)}. In this case the right-hand side of the operator is computed and then they are assigned to left hand side variables.
  • A general rule of thumb is to use blocking assignments when there is a sequential ordering of statements in a cyclic behaviour, i.e., in level sensitive cases (combinational logic) and use non-blocking assignments in case of modelling edge sensitive cases like synchronous concurrent register transfer or latched behaviour.

Let’s take an example to make it clearer.

In the blocking case the value of X is stored in Y and then Y+1 in Z so Z stores X+1. whereas in non-blocking case X is temporarily stored to some location say temp1 and similarly Y+1 to temp2 and then temp1 is assigned to Y and temp2 to Z so here Z stores previous value of Y added to 1.

So now we know different assignment methods let’s visit the behavioural blocks once again.

  • initial block: The abstract behaviour declared by this block is also known as single-pass behaviour because all the statements are executed once and after that this block terminates. When we have a list of statements then we use keywords begin . . . endΒ or fork . . . joinΒ to enclose all the statements of the block.

  • always block: The abstract behaviour declared by this block is also known as cyclic behaviour because statements are executed always whenever the event control expressionΒ is true. Event control operationΒ specifies the condition that must be true in order to kick start the always block. It’s also known as sensitivity list. For example, posedge or negedge of a clock.

This sensitivity list can specify level-sensitive eventsΒ or edge-sensitive eventsΒ or a combination of both. However in practice designers avoid using the 3rd option as the synthesis tool is not able to translate it to actual hardware.

Comma β€œ,” can also be used in place ofΒ β€œor”.

I think it’s enough for this blog. We will continue this in the next blog.

This blog has been submitted by KRSSG, IIT-Kharagpur under the Robocraze Club Outreach Program.

Author: Anubhav Prasad

Leave a comment

Please note, comments must be approved before they are published