Hello everyone this is sha and welcome to vsi point so in this course I'm going to cover all the very log topics from basic level to advanced level in very simple words so if you are a beginner and you are just planning to learn very log you just want to build your concept then you must join this course even if you have some basic idea about verilog but still you are not confident with some Advanced topics then you should Also join this course so in this lecture we will learn about hdls what is HDL what
are the advantages and why we should use HDL we'll learn everything in this lecture so without any delay let's get started so HDL stands for Hardware descriptive language it is a special Ed computer language which is used to describe the structure and behavior of electronic circuit whenever we are talking about hdls so directly or indirectly we are Talking about a piece of Hardware so this language is related with Hardware circuits in early' 70s when we didn't have hdls at that time pen paper and drafting tables were used to describe the specification of the circuit since
now we have hdls so we can simply translate our ideas to the digital circuit hdls include the notion of time and it also supports concurrency so this is the property of HDL whenever We are talking about notion of time so it is basically related with the time delays of digital circuit in real time each and every Hardware circuit have some time delay and hdls include that time delay so this is the property of HDL talking about another property which is concurrency so concurrency is nothing but whenever two things are happening simultaneously that is called concurrency
suppose in a circuit there Are two blocks and both the blocks are executing at the same time so this is the example of concurrency and hdl's also support the concurrency so it is a concurent language however if we are talking about other programming languages like C and C++ so these are not concurrent languages these are sequential in nature so this is all about hdls very log and vhd DL both are Hardware descriptive language so we'll start with very log so very log is a Hardware description language and the current standard is i e 2001 very
log is basically used to describe the lowlevel hardware actually very log is a very flexible language in very log there are some predefined basic Gates and digital circuits which are already saved in digital library of the very log so we can directly use those blocks and that are known as Primitives verilog is a very much similar to C language whenever we Are talking about syntax but still there are some difference between verilog and C language so let's see what are the difference very log is a hardware description language which is used to model electronic system
however C is a general purpose programming language which allows the structured programming hdls have notion of time however C language don't have the notion Of time verilog helps to design and describe the digital system however C helps to build operating system and database compiling interpreters in case of very log the file extension is v in case of C language the file extension is do c so these are some basic difference between verilog and C language now we are moving towards vhdl so vhdl stands for vhsic that means very highspeed Integrated circuit Hardware description language bhdl
are basically used to Model Behavior and structure of digital system at multiple abstraction levels bhdl is a kind of strongly typed language and it is very deterministic vhdl is a is an old language and it has developed in 1980s uh vhdl syntax is nonc type and the advantage of vhdl is that we can easily fix the bugs in vhdl as compared To VAR log so these are the advantages but yes vhdl is strongly typed mean to say whenever we are writing the code in vhdl so code will be a little bit long as compared to
very log so now we are going to see some differences between the veril log and vhdl so veril log used to model electronic system however vhdl used in electronic design automation to describe digital and mixed signal system very log is weekly typed however vhdl is strongly Typed mean to say bhdl is more strict about the syntax beril log is based on C language syntax is very much similar however vhdl is based on Pascal and Ada language verilog is case sensitive bhdl is not case sensitive in verilog we have SIMPLE data types in vhdl data types
are more complex verilog is a new language standard is 2001 i e 2001 however vhdl is an old language and it has developed in 1980s very log is less complex in nature bhdl is more complex in nature so if you are a beginner then I'll recommend you to start with very log then it will be more easier for you to build the concept and after some time you should start vhdl so very log supports four level of abstraction switch level gate level data flow level and behavioral level so in switch level the implementation is done
in terms of switch switches in gate level we Basically talk about logic gates interconnection in data flow level the designing has done in terms of equation mean to say it is based on the data flow how the data is flowing in the circuit based on that the equation has written and the last one is behavioral level which is completely based on the behavior of the circuit so one by one we'll understand each and every level so starting with switch level so at switch level a module can be Implemented in terms of switches so we can
represent the entire Circuit by using Coss transistor and here in switch level n MOS and P MOS are used as switches for the design purpose so we can understand with the help of a small example so here you can see this figure is nothing but a camos inverter circuit so here this is p Moss this is n Moss the input is a and the output is Q two voltage supplies are there bdd and vsss so we'll first focus on syntax so Whenever we are writing a code in switch level then the syntax will be be
Moss name which can be P Moss or n Moss then instance name this instance name is completely optional then the output and then data and control now this is the very log code for this circuit so don't bother about the complete code because in upcoming lectures I'll explain each and every point of VAR log code what is the basic framework and how we can write the VAR code I'll explain each and every Point so for now just focus on the switch level modeling that how can we write a quote in switch level so our point
of interest is this line like how we are writing the switches so first the Moss name which is p Moss then the instance name which is p and then the output data and control which are Q vdd and A so this line is basically for this P mooss circuit here for p Moss input is a then q and then the data is bdd now for this n Moss you can see here The Moss name is n MOS the instance name is n you can write any name here and then output data and control which are
Q vsss and A so this is all about switch level modeling and I hope now you got just a basic idea how you can write a code in switch level so now we are moving towards the next level which is gate level so at gate level module is implemented in terms of logic gates gate level is basically represents the lowest level of Abstraction the basic logic gates are available as predefined primitive actually in the digital library of verilog these logic gates has already saved and we can directly use those Primitives like and or nand nor
any gate we can use so we'll understand that with the help of example so here you can see the syntax first of all we have to write the Primitive name this primitive name is nothing but the logic gate which we are considering then the instance name Name again it is completely optional you can write any instance name even you can skip this part then the output of the gate and then all the inputs so now consider this example and gate here the inputs are A and B and the outputs are output is out so we
can write and one more thing guys since very log is case sensitive so whenever you are writing the Primitive name so it should always be in lowercase characters as you can see here I have written this and gate Name in lowercase so always focus on this point otherwise it will throw an error so here the Primitive name which is and then instance name I have taken G1 and then outputs and inputs output is out and the inputs are A and B so in this manner you can represent a gate you can consider another example here
like nand gate and orgate in this nand gate inputs are ab and the output is y so here simply I have written nand then instance name G2 and then input output Ports which are Y A and B similarly here it is for orgate so this is all about gate level modeling and really it's very simple to represent a circuit in terms of gate level but sometimes the code will be very long because of the interconnection of the circuit so now we are moving towards the data flow level so whenever we are talking about register transfer
level then this data flow level comes into the picture so at this level module is designed by Specifying the data flow like how the data is flowing in the circuit based on that we just need to write the equations so in data flow level signals are assigned by data manipulating equation and design is implemented by using continuous assignment actually we have to use assign statement in data flow level and whatever assignments are there all those assignments are concurent in nature so we can understand the data flow level by using this simple example So as I
told assign keyword is used in data flow level and here you can see in this example I have written this assign then Z equals to X and Y so this X and Y is assigned to zed by using this statement another example you can see here assign P = to Q or R so this Q or R is assigned to P variable so like this you can write a code in data flow level by using assign statement which is a continuous assignment now we are moving towards the behavioral level so the Behavioral level is the
highest level of abstraction which is provided by HDL behavioral level basically describes the system by its behavior in behavioral level different elements like functions task and blocks can be used and two important constructs are initi IAL and always so we'll understand the behavioral level with the help of example so here I have taken a two cross one multiplexor so as we all know in 2 cross one multiplexor the simple Behavior is when the select line is high then input i1 is assigned to output and when the select line is low then input i z is
assigned to out so similarly here I have written this always at i0 i1 select so this is nothing but a sensitivity list so for now don't bother about this code actually this is not a complete code this is just a snippet which which I have taken from 2 cross one multiplexor code so I'll tell you each and everything in upcoming lectures so For now just focus on the behavior of 2 cross one multiplexer so here I have written if select mean to say when select line is high then input i1 is assigned to out and
when it is low then input i0 is assigned to out which is the simple behavior of two cross one marks so in behavioral level modeling we can define a circuit on the basis of the behavior so this is all about behavioral level modeling I hope you got all the concept So a module is the basic building block in very log so what is the meaning of basic building block you can understand that with the help of an example so consider a building a simple building or your home so the basic block is Brick with the
help of bricks the entire building has made so similarly in very log the module serves the same purpose this module is the basic building block and it can be an element or a collection of lower level design blocks so these Modules provide the required functionality to the higher level blocks through its Port interface but it hides the internal implementation so in other words we can say that it provides the flexibility to the designers to modify the module internals without affecting the rest of the design so maybe few lines are just not clear to you but
don't bother about that because I'm going to explain each and every term so just consider the basic framework of Very log code so whenever you are writing a very LW code for any digital circuit then what should be the basic format so here we are going to know about that so as you can see here the code is starting from module and ends with end module so here module signifies the Declaration of the module and end module signifies the termination of the module so this is about the beginning and end of the module now after
module we need to write the module name now This module name can be anything we can write any name we can give any name based on the circuit and after writing the name in parenthesis we just need to write all the inputs and outputs means the list of ports we just need to write here then we have to declare the ports whether that Port is input or output so we have to write that so this is about Port declaration after that we just need to write the statements and these state ments are nothing but the
functionality Of the circuit it can be written in terms of Behavioral modeling or in data flow level or in gate level or switch level and last but not the least this semicolon represents the termination of the statement so it is very important to terminate a line so this is all about the basic framework of very l code I hope you guys are getting that after seeing some example it will be more clear to you okay so we are now moving towards Instantiation what is the meaning of instantiation in very log so instantiation allows the creation
of hierarchy in the very log description here the hierarchy means with the help of some sub modules we are just trying to make the main module the top block with the help of some sub modules and this is nothing but the hierarchy and it can be done by using instantiation so it is a process of creating object from a module template and the objects are Called instances so you can understand the instantiation with the help of a small example suppose we just want to represent or we just want to design a full adder circuit with
the help of half erer circuit so we just need to write a module for half ater circuit and then we instantiate that module two times to create two copies of that half adder circuit so this instantiation is nothing but creating the copies of Hardware circuit in very log nesting of module is Illegal means we cannot Define one module inside another module so now we will consider an example so here a 4 cross one marks by using 2 cross one marks as I I was talking about the hierarchy so yes here I'm trying to represent a
4 cross one multiplexer with the help of 2 cross one multiplexor so as we all know three blocks of 2 cross one multiplexor is requ IR ired to represent a 4 cross one multiplexer as we can see here in this figure three 2 Cross one multiplexor block is there this this and this four inputs i0 i1 I2 and I3 four inputs are there two select lines S1 and s0 and one output out is there now how can we represent a 4 cross 1 marks by using 2 cross 1 marks we can see here so first
of all we need to write a very log code for 2 cross one multiplexer so now you are familiar with basic framework of verilog code so I hope you guys are now just capable to understand This code so I'm starting with module then module name which is MX 221 then listing of all the ports so here I i1 are nothing but inputs then select line which is also an input input and then out then Port declaration i0 i1 select is our input and out is output then here I'm using behavioral level modeling to write the
code so always at i0 i1 select so this is the sensitivity list and I'm using always block here then if select whenever the select line Is high then i1 is assigned to out otherwise this i z is assign to out so this is representing a 2 cross one multiplexer now our Target is to describe a four cross one multiplexor by using two cross one multiplexor so we just need to create three copies of 2 cross one multiplexor as you can see here in this figure so now we are moving towards the main module which is
4 cross one multiplexer so here you can see module then MX 4 to one then Port Listing here four inputs two select lines and one output then Port declaration i0 i1 I2 I3 and S1 s0 then output is out here one new term is there which is wire so for now just consider this wire X1 and X2 as X1 is output of this multiplexer and X2 is output of this m multiplexer so for this last 2 cross one multiplexor X1 and X2 are two inputs s0 is Select line and output is out this is the
meaning so here I have instantiated three times because I just Want to create three copies of multiplexer three copies of two cross one multiplexer so M1 M2 M3 are the instance name and then I have written the ports now to be very careful about this ports because whatever order we have given here in the sub module the same order we need to follow while instantiating that so here you can see first of all two inputs then select line then output so same order we are following here two inputs select line And then output so similarly
I have instantiated three times to create three copies for last multiplexer X1 to our inputs s z is Select line and out is out so this is all about representing four cross one multiplexor by using two cross one multiplexor so I hope that instantiation is clear to you now we are going to talk about verilog keywords so veril log is case sensitive in nature although we can use underscore dollar and alpha numeric characters to Represent the keywords but there is a proper format and here you can see the correct format is this one the keyword
should always be in lower case and it should not start with underscore or a number like here this format will throw an error in your code so avoid using this style and always prefer this style it is recommended so this is about the very log keywords now we'll talk about commands so so comments are basically used for the documentation purpose Actually it improves the readability of the code so whenever you are writing a code so you should always use writing commments it is always recommended because it's very important to write why you are using that
particular line when you'll open that code after 10 days or after after a week or after 1 month month then maybe you will forget how that line works or why you have written that particular line in your code so for that purpose comments will be added to Your code so there are two types of comments single line comment and multi-line comment whenever you just need to write single line of comment then you should use this double slash and in case of multi-line comment you can start that with this slash and sign and you can close
with asri and slash so this is all about comments we can understand it with the help of example so here in first line I have given single line comment so here I'm using Double slash and write the comment uh one more thing guys this comment will not be considered for the simulation your statement will be terminated here so whatever comment you want to write you can write by using this double slash and in case of multi-line comment you can start with SL and estri sign and you can terminate that by using asri and slash so
this is multi-line command so starting from simulation Simulation is used to verify the functionality of the digital design that is modeled using hdls like verilog so simulation is basically to verify whether your code is working correctly or not suppose you have written an RTL and you just want to check whether your code is working properly or not so for that purpose you can perform simulation and for that simulation you just need to write the test benches now what is test bench in test bench we give a set of Inputs called stimulus and whatever outputs are
generated with the the given input we just evaluate whether the circuit is working correctly or not with the help of those generated output waveforms and this complete process is called the simulation so for simulation Pro purpose we apply different input stimulus to the design at different time to check whether the RTL code behaves in intended way or not so we just need very lock module Which is RTL and then test bench with the help of these two things we can perform the simulation and whatever output has created after simulation we can evaluate the result whether
the RTL is giving correct result or not so this is all about the simulation now we'll talk about the synthesis so synthesis is a process in which digital design that is modeled using HDL is translated into an implementation consisting logic gates so In simple words we can say that synthesis is used to convert the RTL into net list it will just make an optimal design based on the working strategy which we are using and also give the consumption of resources as available so yes in case of synthesis we just require very log module there is
not any kind of test bench so for synthesis operation we use RTL and we can use either sic or fpga to perform the synthesis operation so most of the People have seen the fpga board in your college lab it is a green color board and we just need to dump the program into that boat and we can check the functionality we can check whether the uh RTL is working correctly or not so this is all about the synthesis process one more thing in synthesis since we are not uh giving any test bench here so there
is not the concept of time delay in case of synthesis because already we are verifying the functional on Hardware So time delay is only considered in case of simulation and not in synthesis process so now we'll talk about the design methodologies so in very log there are two types of design methods top down and bottom up so in top down the flow of design is from top to bottom we are starting from top level block block and then we are dividing each and every block into sub blocks until we reaches to the leaf shell which
is the smallest Possible block and in bottom of design we just start from the bottom level that is from the lowest possible block and then we combine those blocks to make the macros and these macros will again combine to make the top level block so here the flow is from bottom to top so one by one we'll talk about in more detail so starting from top down design method so here we first Define the top level block and then identify the sub blocks necessary to build the top level Block these subblocks are further subdivided until
we come to the leaf cell which cannot be further divided so here you can see in this figure we have the top level block this one so we have divided this top level block into subblocks and again these subblocks will be divided into Leaf shell and leaf shell is nothing but the smallest possible block which cannot be further divided so here the flow is from top to bottom and that that's why this Methodology is called top down design methodology the design is Flowing from top to down now we'll talk about bottom of design methodology so
here we first identify the building blocks that are available to us and then we just combine these building blocks to build a bigger block so these cells are then used for higher level blocks until we build the top level Block in the design so here you can see in this figure we just check what are the blocks which are available To us so here these leap shells are available to us so we just combine these smaller blocks and make the macros now these macros will again combine to form the top level block so here you
can see the flow is from bottom to top and that's why it is called bottom up design methodology we are starting from bottom level from smallest possible block and then we we are moving towards the top level block so I hope it is clear to you so guys talking about the data types so A data type in programming is a classification that specifies which type of value a variable has and what type of mathematical relation like logical operation or arithmetic operation we can apply to it so that it will not cause any error in the
system so this is about the data type now talking about the data types supported by the very log then there are mainly two data types register and net so one by one we'll cover so starting from register data type so Register data types are are mainly used to store the values it holds the value but it doesn't mean that it's going to produce Hardware register this data type is totally different from Hardware register it is simply a data type which can hold a value until we assign a new value to it it is commonly declared
by the keyword reg and the default value of reg data type is unknown which is X in register data type there are different classes like reg integer real time so We'll cover in upcoming lectures so now we are moving towards net data type so Nets represent the connection between the hardware elements and it must be continuously driven mean to say it cannot be used to store the values Nets are declared primarily with the keyword wire and the default value is Zed again the net data type has different classes like wire then wired and wired or
try triy and TR or TR so we'll cover all these classes in upcoming lectures so Now we are moving towards values and signal strength so very log supports four different value levels and these are 0 1 x and Zed so 0 represents logic zero means false condition one represents logic 1 which is true condition X represent unknown logic and Zed represents high impedence so this is about the value levels now talking about the strength levels so verilog support eight different strength levels and these are Supply strong pull large weak Medium small and high Z and
here in this table you can see the strength level is increasing from bottom level to top level means as we are moving from bottom to up the strength level is increasing now the twist is that when we apply two different strength level signals as a input to the wire then this higher strength level signal will be reflected at the output and when we apply the same strength level signals as the input to the wire in that condition the output Will be unknown so you can understand from this figure in first example I have given two
inputs Supply one and pull one and you can see at output the supply one has reflected and the reason is fly one has a higher strength level as compared to the pull one in second example I have given two inputs strong one and strong zero since both the signals are in same strength level so in output there is unknown value so yes I was talking about these two conditions now we are moving Towards the last topic of today's lecture which is Port assignments so we have three different types of ports input output and inout inputs
and outputs are unidirectional however in outputs are bidirectional in nature talking about the input Port So within the module it is of wire data type but externally when we assign any variable to this port then it can be of red or net data type now talking about the output Port so yes in Internally it can be of reg or net data type but externally it is always be of net data type that is wire data type now in in outputs it is always be of wire data type it we can never assign reg data type
to the in output so this is all about the port assignment so Nets basically represent the connection between the hardware element it must be continuously driven mean to say we cannot use a net data type just to store the value the keyword which is used for Net data type is wire and the default value is z there are different classes in net data type and these are wire wired and wired or try try and try or tryr so one by one we'll cover these classes in detail so starting from wire so here you can see
in this end gate the inputs are A and B and the output is C so here the output C is net data type mean to say it is continuously driven as we'll give the different values at the input side according to that the output Value will change it will not store the value because it is continuously driven so here I have taken a half adder circuit the inputs are A and B and the outputs are sum and carry so here in very log code you can see module name is half add then the different ports
are a b sum and carry then I have just uh written the port declaration input a comma B output sum comma carry now I have taken this sum and the carry as a wire data type and then I'm using assign Statement as we have seen in a previous chapter that with assign keyword the left hand side variable should be of wire data type we cannot use a reg data type here that's why we have taken sum and carry as a wire data type now A exort B value is assigned to sum and A and B
value is assigned to carry so this is about the very log code of half adder circuit using wire data type now we can see there are different classes like wired or wired and Supply zero Supply One so what are the advantages of wired or and wired and so we'll cover that so here in this diagram you can see two gates are there and and or in and gate two inputs A and B and in or gate two inputs c and d and the output of both the gates are just connected and the final output is
y now the problem in the circuit is that if we use Simple wire data type for output y then it will give an indeterministic value because we are assigning two Different values to the the output Y A and B and then C or D so simulator will get confused that which value it has to just assign to the output y but if we use wired and or wired or for output y then this problem will not be there because in case of wired and as you can see in the second example I have taken wired
and logic here so the final value which is assigned to Output Y is the end of A and B and C or D as you can see here in this block Y is nothing but the End of A and B C or D so here the output will be more accurate not an indeterministic value similarly you can use wired or also here so this is about wired or and wired and now in this example we'll get an idea about Supply one and Supply zero so here in this very log code I have taken four inputs
AB B CD and one output y then Supply 1 vdd and Supply zero ground then different logic gates are there or and exor and accordingly I have given input and Output to these Gates so this is about the supply zero and Supply 1 I hope you got the idea that how you can use Supply Z and Supply 1 while writing the very log code now we'll talk about the numbers that how you can represent a number while writing a very LW code what is the correct format so the syntax is Si single quote then base
and then number so here size is nothing but total number of bits and base represent the Base which you are using for that number and then the actual number so here in first example you can see I have written one t B1 so here one is representing the total number of bits which is one and B is representing the base which is binary three so this is nothing but a logic one as you can see here it is a one bit number similarly in second example I have written 8 tick h21 now here this 8
is representing total number of bits that is 8 and H is Nothing but the base value so here the base is hexadecimal and as we all know in hexad decimal we represent a number by using four bit binary so here for two we'll represent that by using four binary bits and one is also represented by using four binary bits as you can see here so this is nothing but an 8 bit number similarly in third example also I have given 12 tick H A35 so 12 is nothing but 12 bits then H is the base
which is hexadecimal so here we have to Represent each number by by 4 bit binary as you can see here so this is about the basic syntax of the numbers and the understanding that what it is representing now we'll talk about some more points so here you can see for binary we have to use B then for octal it is O for decimal it is D and for hexadecimal it is H these we have to use while giving the base value now we'll talk about the use of underscore while writing a number Actually underscores are
used to improve the readability of the code whenever we are talking about a 64bit number or a 32bit number then total number of bits are really large and it will not be that readable so just to improve the readability you can use the underscore to represent the number as here you can see it is more readable okay and now we will talk about the extension which is 0 x and z extension so in first example I have written 4 tick B X0 actually the basic concept behind the extension is that whatever the total number of
bits here we have to complete that and when the number here is not completing the total number of bits then then we use the extension concept just to complete the total number of bits so here I have written four tick B x0 so it is representing a 4 bit number and the base is binary so total four bit should be there but here we can see base is binary and the number is x0 so this is 0er this is X but still only two bits are there two more bits should be required to represent the
number in four bits so here we simply extend the left hand side number to complete the four bits so this is nothing but the X extension similarly in second example I have written five tick D1 now the five is nothing but total number of bits so here in this number the total bit should be five and the base is decimal so in decimal the number one can be Represented at as 1 but still the total number of bits should be five so just to F fulfill that we have to extend by using zero so here
we are using zero extension to complete the total number of bits now in third example I have written 16 tick h z 6 so here total 16 bits should be there base is hexadecimal so again we have to represent each number by using four binary bits so for six I have written 0 1 0 and for Zed 4 bit Z but still there is only 8 Bits And We require 16 bits so just to fulfill the 16 bits we are using Zed extension here so now you can see the total number of bits are 16
here so this is about the 0 x and Zed extension I hope you got the idea so so verilog supports different register data types and these are reg integer real and time so reg data type is the most widely used data type talking about the integer so it is basically used for the loop counting purpose real data type is used to store The floating Point numbers and the time is used to keep track of the simulation time so one by one we'll understand so starting from basic introduction of register data type so it is used
for the data storage purpose it can hold the value and it is declared by the keyword reg the default value is unknown and the different classes of register data types are reg integer real and time so here we'll see an example of reg data type so here you can see you can declare a Reg data type in single bits or in multiple bits so in single bit simply you have to write reg and then the name of the variable so it will represent a single bit register variable now in case if you want to declare
a register data type as a multiple bit then you have to write reg then the size and then the name of the variable so here it is representing an 8 bit buses because of this size so now see this example here I have taken reset as a register data type Then in initial block I have assigned different values to the reset variable so initially the value is zero then after 10 time units delay I have assigned the value one and then again after the 10 time units delay the value is zero so here the meaning
is since reg data type stores the value so initially this reset will have the value zero and at 10 time units the value is changes to one and then this variable holds the value one until it will get the another Value zero at additional 10 time units so this is the meaning of the register data type now we'll talk about the integer data type so it is a general purpose register data type and it is declared by the keyword integer and it is declared by the keyword integer it stores the values as assigned quantities mean
to say you can assign negative and positive both the numbers to the integer data type it is generally used for the counting purpose and it is synthesizable In nature the default value is unknown and the default width is 32 bits mean to say if you are not giving any width while declaring the integer data type then by default it will be 32 bits now consider this example here I have taken count and N num as a integer variable and then I have assigned the values for count it is four and for n num it is
-7 so here you can see how you have to declare integer variable and how you can Assign the values to the integer variables now we'll talk about the real data type so the keyword real is used to declare the real data type it allows decimal and scientific notation and it is mainly used to store the floating Point numbers it is non synthesizable in nature mean to say it cannot be used for synthesis purpose and the default value is 0.0 whenever we assign a real number to the integer variable in that condition The value will be
rounded off to the nearest integer consider this example here I have taken two real variables count and nunum this is the Declaration and here I have assigned the value for count it is is 4.76 and for new num it is - 1.3 now here you can see A and B are two different variables a is of integer data type and B is of real data type now for B the value is - 6.5 I'm assigning this real number to the integer variable so the real number Will be rounded off to the nearest integer so the
value of integer a will be - 7 here so I hope you got the point how we can round off the value to the nearest integer so this is all about the real data type now we'll talk about the time data type so it's a special time register data type which is used to store the simulation time it is declared by the keyword time time variables are unsigned in nature And width is generally 64 bits it is non- synthesizable in nature and the default value is unknown so whenever I'm telling that this particular data type
is non-s synthesizable in nature so the meaning is that whenever you are performing the synthesis operation then that variable will be just ignored by the system now consider the example of time data type so whenever we are talking about the synthesis so in that condition we are just uh uh implementing The real Gates we are using the real Gates so at that time there will not be any use of time delays or this time data type the actual delay of the gate will be considered in that condition and that's why we are telling that the
time data type is not synthesizable in nature now consider this example here I have taken this new sim time variable and this is a Time data type and here I have assigned dollar time to this variable Now this dollar time is nothing but the system function which gives the current simulation time so here simply the current simulation time will be stored to this variable so starting from vectors so Nets or reg data type can be declared as a vectors mean to say you can decare regge or net data type it can be of one bit
or it can be of multiple bits so if bit width is not specified then the default size is scalar mean to say one Bit these vectors represent the buses and vectors are declared and it is specified by the range R1 and R2 so here you can see this R1 is nothing but the MSB and the r R2 is nothing but the LSB so in this example you can see the first one is VRE XY Z so it is nothing but the single bit variable because I have not given any Vector here so by default it
will be scalar that is 1 bit in second example I have written wire 15 down to zero data so here data is a 16bit data in third example I have written yre then 0 to 31 sum so here sum is a 32 bit data uh as I have told this zero is representing the MSB and this 31 is representing the LSB similarly here also this 15 is nothing but the MSB and zero is nothing but the LSB so remember just one point whatever is there at the left hand side that is representing the MSB and
whatever is there at the right hand side that is representing the LSB this is the simple idea now we'll talk About the arrays so in very log arrays are allowed for reg integer time and real data types whenever uh we are declaring the multi-dimensional array we can declare it with any number of Dimensions here you can see a very important difference and it can be asked in your exam or in your vaa that what is the difference between these two representation so just understand it carefully so the first representation is nothing but a register bank
here I have Written reg 7 down to zero register Bank 15 down to zero so this is representing 16 8bit resistors however in second example I have written reg num 31 down to zero and this is representing an array of 32 1 bit numbers so you can see the difference first one is 16 8 bit registers and the second one is an array of 32 1 bit numbers so I I hope you got the idea now here I have considered the different array examples first one is Representing the onedimensional array here I have taken reg
then the array name which is reg a and then the vector which is 0 to 7 so here it is representing an array of eight 1 bit registers as you can see here this is a one dimensional array similarly here I have taken but this is a 2 bit array similarly here here I have taken another example this is representing a two-dimensional array so reg then array a which is the array name and then the Dimension so you can correlate this with um a matrix in Matrix we have rows and columns so here also you
can consider this Vector for rows and this Vector for columns so in this figure you can see the two rows this and this and four columns 0 1 2 3 similarly here I have taken another two- dimensional array which is y array W 0 to 7s and 0 to 3 so here total eight rows are there and four columns are there now we'll talk about the memories so memories are modeled as A one dimensional array of registers so it is basically used to model register files RS and Rams each element of the array is known
as the element or a word and you can address these elements by using the index number these elements can be of one bit or it can be of multiple bit as I have uh just explained in the vectors part now you can see here we generally use onedimensional array uh for the memory purpose so here you can see this Is reg then and Me 1 bit 0 to 1 023 so this is representing a memory m 1 bit with 1K 1 bit words so here this 1K is nothing but the depth and each element is
of one bit similarly in second example I have taken reg 7 down to 0 Mite 0 to123 so this is representing the a 1K memory mean to say width is 1K and each element is of8 bits this is the meaning so simply just the idea is the first Vector is representing the width Like this thing and the second Vector which is the last one is representing the depth of the memory which is this one so hope you got the point now we'll talk about the parameters so parameters cannot be used as a variables it is
a constant value so now the question arises if we can simply declare a constant then why we should use parameters and what are the advantages so the thing is that if you are using parameters and if you are Declaring some variables as a parameter then it will help to customize your code consider an examp example of memory designing if you are designing an 8 cross 16 memory here the width is 8 and the depth is 16 so you will write the code according to that after some time if you want to write the code for
uh 16 Cross 256 memory where the width is 16 and the depth is 256 so simply by changing the parameter Values you can change the entire code for the next block mean to say you will not need to make the changes in that code just you have to make changes in the parameter value and here you have done so this is the advantage of parameters now the last topic of today's lecture is the string so strings can be stored in red strings are nothing but the all about the characters uh basically we will talk about
the sequence of characters in strings so Each character is represented by eight bits and these sequence will be enclosed by the double quotes so here you can see I have declared a string which is string value and this is a register type string and the vector I have taken is 8 into 10 down to 1 now the reason of taking this Vector is uh this one now the reason of taking this Vector is uh because each character is of 8 Bits And here I'm assigning 10 different characters so that's why here I have taken 8
into 10 So this is about the Declaration of string now we have to assign a value to this string variable so here I am assigning this vsi point to the string variable so like this you can declare a string and you can assign the sequence of characters there are some special characters of string like back sln which is used for the new line back SLT for the tab back slash percent which represents the percent then double back Slash is used for the single backs slash and back SL double quote is used for the double quotes
in any programming language like C C++ Java there are some operators which are built in in that language it can operate on some data items like numbers characters and some values in very L there are set of operators and some of them are very similar to high level languages like C and C++ but some of the operators are more specific in case of very log which Have direct connection with Hardware that verilog supposed to model so operators act on operant to produce desired result now different types of operators are there in very log and these
are arithmetic operators logical operators bitwise operators then equality relational reduction shift operators and then concatenation and conditional operator so one by one we will cover each and every topic so starting from arithmetic operators so There are two types of arithmetic operators un and binary so unary operators here The Operators plus and minus can work as un operators so basically it is used to determine whether the operant is positive or negative so here in this example I have shown -4 and positive 5 so in this manner you can represent a number whether it is a positive
number or negative number so this is the use of unary operators now we will talk about The binary operators so binary means two so in binary operators we consider two operants and then perform different binary operators and these are add subtract multiply divide mod modulus and exponential so we will understand these things with the help of some examples so here I have taken a and b as a register vectors and then few integers d e and f now in first example it is a multiplied with B so a is a 4bit value 4 take B
0 0 1 0 and B is also a 4bit value 4 tick B 0 0 1 one now then you perform the multiplication operation between A and B then you will get the answer 4 tick B 0 1 1 0 guys I'm requesting you to solve each and every example on your copy and then match the answer with my answer so in this manner you will get how you can perform these operations okay so in second example here I'm taking this D ided by E so here the D value is seven and the E value
is four so when you'll divide this D by E then the result will Be 1 now the value will be truncated also you can perform a + b b minus a and then e exponential F so in this manner you can perform different arithmetic operations now here I have considered some examples with unknown values so remember one thing if you are using arithmetic operators and if one of your operant or both of the operant is having unknown value then your final result will be unknown only even if the single bit is unknown then also the
overall Result will be unknown in case of arithmetic operators here you can see value of a is 4 TI B 0 0 1 x and B value is 4 tick B10 1 1 now the sum equals to A + B so when you will perform the addition operation then the final result will be unknown because one of the operant is consisting unknown value so the overall result will be unknown only also here I have considered some modulus operators also so 17 modul 4 and the result will Be one so whenever you will divide 17 by
4 then the remainder will be one so here the answer is 1 similarly 16 modul 4 here the answer will be zero then - 7 modul 2 and 7 modul minus 2 now the last two examples are really very important so focus on these examples whenever your any one operant is negative either first or second then the answer will be according to your first operate basically the sign of the result whenever the sign of first operant is Negative then the overall result will be negative only and when the first operant is positive then the overall
result will be positive only so here you can see this is - 7 modul 2 so the result will be minus one why minus sign because of this first operate similarly here 7 module min-2 so here the result is + one so why this plus because of this first operate so in this manner you can perform the arithmetic operations now we are moving towards logical operators so We use logical operators to define the conditional statement the result of logical operators is always true or false so um when it comes to define the conditional statement like
if then given condition so when the condition is true then do this else do that so in that kind of situation we use logical operators now different types of logical operators are there and these are logical negation logical and and logical or consider the example here so a value Is five and B value is zero so here in first example I have taken a logical and B now here I can see the a value is true but the B value is false false so the overall result will be false on me similarly a logical or
B so in case of logical or if either of the operant is high then the overall result will be high only then negation a and negation B since a is high then its negation will be logic zero and B is a false value so its negation will be logic one only Similarly some unknown value like here a is 2 TI B 0x and B is 2 TI b 1 0 so whenever you perform a logical and B so the result will be unknown only because one of the operant consists this unknown and because of this
the overall result will be unknown only so this is all about logical operators now we will talk about the bitwise operators so bitwise operators performs the operation between the bits it performs bit by bit operation on two operants it takes each Bit in one operant and then perform the operation so different types of bitwise operators are bitwise and bitwise or bitwise negation then bitwise exor and exor here you can see the table for bitwise and or exor exor and negation I have considered three values 0 1 and unknown and according to the table you can
see whenever you are performing this bitwise and then what result you will get in case of bitwise or and other bitwise operators so here in these Examples you can see x y and Zed values whenever you perform this negation of X so X is nothing but a 4bit value for tick B 10 1 0 and whenever you want to perform the negation operation so we need to perform the negation of each bit each bit of x value so the result will be 4 TI B 0 1 0 1 and this is nothing but the negation
of these bits respectively similarly here X and Y so here we have to perform the end operation between X and Y and this is Nothing but the bitwise end operation so the result will be 4 TI b 1 Z similarly here X or Y so we need to perform the or operation between X and Y similarly you can perform the other operations like X xor Y X xor Y X and Zed now here since this Zed variable consist this unknown value so here when you perform the end operation between X and Zed so the second
bit this one the result will be unknown only because when you perform the end operation between unknown and One so the result will be unknown only so here the final result is 4 TI b 1 0 x0 so this is about the bitwise operators now we will talk about equality operators so basically we have two types of equality operators logical and case logical equality logical inequality then case case equality and case inequality so logical equality is synthesizable in nature however case equality and inequality is non Synthesizable in nature the result of equality operator is logic
one or logic zero mean to say it will be of single bit only either true or false the important difference between The Logical equality inequality and the case equality and inequality is that in case of logical equality we will not consider X and Zed values however in case of case equality we consider the X and Zed values here you can see the symbol for equality and inequality now in most of The interviews the interviewers may ask this question that what is the difference between this double equals and triple equals sign so here you need you
need to say that double equal is indicating The Logical equality and the triple equal sign is indicating the case equality okay so here you can see the examples a value is four B value is three and whenever you'll check whether a equals to B so if this expression is true then the result will be true that Is logic one and if the result is false mean to say if the expression is false then the result will be logic zero only so here you can see a is 4 and B is 3 so these two values
are not same so this expression is false so the result will be logic Zer only similarly here x not equals to Y so we need to check whether this expression is true or false so x value is 4 tick b 1 0 1 0 and Y value is 4 tick b 1 1 0 1 so these two values are not same and according to this Expression X is not = to Y so this expression is true so the result will be logical 1 only similarly x equals to zed we have to check whether the x
is equal to zed or not so here The Zed is 4 b 1 XX Z now we are using the logical equality and this logical equality can't consider the X and Zed values so here the result will be unknown only whenever you are applying The Logical equality or inequality and your operant consist the unknown or high impedence value in that Condition the result will be unknown only similarly here I have taken the case equality so whether this Zed is equal to M or not including x and z so you can see this Zed is 4
tick b 1 XX Z and M value is 4 TI b 1 XX Z so both the values are same so here this expression is true so the result will be logical one only similarly here Z equals to n whether this expression is true or false so this is false you can check here The Zed and N values these two values are Not same so the result will be logic Z so in this manner you can perform the uh equality operation s now we will move towards the relational operators so four types of relational operators
are there greater than less than greater than or equal less than or equal also it returns a logical value either true or false mean to say a single bit output value here you can see the symbol for relational operators and then we will consider some examples so Here a is 4 B is 3 now we have to check whether this a is less than or equal to b or not so you can see this expression is false because a is greater than b so here the result will be logical zero only similarly here a greater
than b so we can see a is 4 B is 3 so this expression is true so the result will be logical 1 then y greater than equal to X so we can see Y is four B 11 1 01 and X is vtic b 1 x so we have to check whether the result will be logic 1 or Logic zero so here in this third example you can see the expression is y greater than equal to X now the Y value is 4 tib 1 1 0 1 and the x value is 4 tick
b 1 1 0 so yes Y is greater than x so the result will be logical 1 now in the last example the expression is y less than Zed since the Zed value consist the unknown for TI b 1 x so we cannot determine whether this Zed is less than y or greater than y because of this unknown and the final result will be Unknown so I hope you got this point now we will talk about the reduction operators so we have different types of reduction operators like and or nand nor exor and exor so
in case of reduction operators we consider the single operant it performs the bitwise operation on a single Vector operant and then yield the one bit result either true or false so here you can see the symbols for reduction operators reduction and nand then or nor exor and exor Then we will understand this operator with the help of some examples here I have taken X = to 4 tick b 1 1 0 when you will perform the end operation of this x then simply the end operation between the bits of X so 1 and zero and
1 and zero and the final result will be one tick b0 similarly you can perform the or of X so bitwise or operation we have to perform so 1 or Z or 1 or zero and the final result will be one tick B1 so in this manner you can perform the Reduction operation also reduction exor and exor can be used for even or odd parity generation of our vectors so now we'll talk about these shift operators so shift left shift right or arithmetic shift left arithmetic shift right right so we have four types of shift
operators so in case of regular shift operators whether it is shift left or shift right the vacant bit positions are filled with zeros however in case of arithmetic shift operators it uses the context of The expression to determine the value with which we can fill the Ved bit mean to say in case of arithmetic shift operation we have to check whether the given number is signed or not and according to that the vacant bit has spilled so it will be more clear when you will see the example so here the x is 4 tick B
11 1 0 0 when you will perform the 1 bit shift right operation so the result will be 4 tick B 01 1 0 so whenever you will shift this number Right side by one bit so here I have f the MSB bit MSB means this bit final bit so this bit is filled with zero because of this regular shift operation similarly here when you'll perform the 1 bit left shift operation so in that condition also the LSP position is filled with zero but when we consider the arithmetic shift operation so in that condition so
here if we consider this x value as a signed number and then we want to shift this x value Right side by one bit then the result will be 4 tick B 11 1 1 0 so here the vacant bit is filled with one why because of this MSB bit so I hope this example is clear to you also integers a b and c and we are considering these as a signed data types now a is zero B is - 10 and C is nothing but a + 3 bit arithmetic right shift of B and
then we have to perform the addition of these two so here the result will be minus two of decimal and this is because of the Arithmetic shift you can check by solving these examples and you can match your answers now we talk about the concatenation operators so basically it provides a mechanism to append multiple operant the operant in case of concatenation operator mean to say we cannot use unsized operant in case of concatenation operators also these operant can be scalar Nets or registers or vector Nets or registers so consider this example here a b c
and d four Variables then I have taken y equals to B comma C in concatenation operator so here Order wise we need to put the B and C values so B is nothing but 2 TB 0 0 and C is nothing but 2 tick b 1 Z so here the final result will be 4 tick B 0 0 1 0 similarly in second example a comma B comma C comma D then 3 tick B 0 01 so here we need to put the values at as per this order so first of all a value then
B then C then D and then this three bit value 0 0 1 so the final Result will be 11 tick b 1 0 1 0 1 1 Tri 01 so here we are nothing but appending the bits in third example I have written a comma B of Z and then C of one so B of0 nothing but the zeroth bit of B variable which is Z and C of 1 is nothing but the first bit of C variable which is 1 so the final result will be 3 TB 101 and this last example here
a comma now this is the replication operator here the B value will be replicated two times similarly here the C value will be replicated three times so the final result will be this one so you can check by solving this expression so this is about the concatenation operator now we will talk about conditional operators so it consist three operant condition expression then true expression and false expression so first of all we need to check this condition expression if this expression is true then the output will be nothing but this true expression Otherwise the result will
be false expression this conditional operator can be of nested type mean to say here in case of true expression and false expression again we can use the conditional operator so nesting is allowed here in case of conditional operator conditional operators is very much similar to multiplexer you can compare this operator with multiplexer so here I have taken 2 to one multiplexer the select line is Conditional expression so when this conditional expression is true then this true expression will be assigned to out otherwise this false expression will be assigned to out when this conditional expression is
false so I hope you got the idea now this is the last topic of today's video which is the operator precedence so whenever multiple operators are there in a given expression then you need to remember this table what is the Precedence of Different operators so here you can see the unity operators has the highest residence then multiply divide modulus then add subtract shift relational equality and then reduction in case of reduction operator you can see here and and and then exor xor and then or and nor so this is the Precedence from lower to higher
then logical and conditional so it's better to use parenthesis Whenever there are multiple operators so question one is find the value of A and B from the given expression here a is 1 bit right shift of Y and B is one bit right shift of Y but the difference is in first case there is logical right shift operator however in second case that is B value there is arithmetic right shift operator and the Y value is 1101 so simply you have to use the logical operator first and then the arithmetic shift operator so quickly pause
the video and solve the question And then you have to match your answers with my solution so I hope you have solved the question so let's come to the solution so yes a value is nothing but the logical right shift of by by one bits so whenever you are shifting the Y value by one bits so you have to append zero value in MSB position because we have already discussed this thing in operator's video okay so here you will get Y is 1101 when you will shift this value by one bit towards the right side
then the value will be 11 1 0 and in MSB position the value will be zero so here we insert the zero value so the final value of a is 01 0 similarly in second case there is arithmetic right shift operator so when you will shift the given number by one bit towards the right side then because of the arithmetic shift operator the MSP Position will be appended with the One so here the Y is 11 1 01 after shifting it will be like this and the MSP bit will be one again so this difference
is because of the logical right shift operator and arithmetic right shift operator so the question two is if p is a vector of length 10 bit then find the value of P for the given expression so here you can see this is the concatenation operator and I have explained very well in previous video What is concatenation operator and how we can use use that operator so here simply you have to concatenate different values which is um 2 tick B X1 then 3 tick B 10 1 then 2 tick b 1 Z and then there is
a replication operator so you have to replicate one tick one two times so let's see what will be the final value of P so I hope you have solved the question and now we can see this solution so Simply there is a concatenation operator so the P value will be first of all 2 tick B X1 then 3 TI B 10 1 then 2 tick b 1 and then the replication operator which is 2 * one t B1 since this p is a 10 bit number and here we are getting nine bits only so we
need to insert the zero in MSB position so now this is the complete answer the P value is 0x 1 0 1 0 1 means 10 bit number I hope you got the same answer now coming to question three Question three is find the value of Q for the given snippet here m is 2 tb10 and N is 2 TB 1X now we have to assign to Q variable and there is a conditional operator and here the expression is if m is less than n if this expression is true then we have to assign 2
tb10 to Q otherwise in case of false expression the Q value will be 2 TB 1 1 so simply you have to check whether the M value is less than n or not and according to that You can assign the Q value so quickly solve the question and then match your answers so I hope you got the answer here since we are using a relational operator and in my previous video I have already explained that relational operator is not able to merge X and Zed values so simply here the result will be 2B XX why
because this relational operator will not consider the x value and because of that the answer will be unknown only now the Question four is evaluate the value in the given snippet m is 5 TI b 1 X1 Z and N is 5 TB 1 X1 Z simply you have to check whether these two numbers are equal or not in first case there is normal equality and in second case there is a arithmetic equality so apply the operator and get your answers hope you have solved this question now we can see the solution so in first
case you have to check whether the m is equal to n or not there is Normal equality so m is 1 X1 Z and N is 1 X1 Z since both the value is same but this equality operator cannot consider X and Zed values and because of that the answer will be unknown only but in second condition where we are using the arithmetic equality operator M and N value is exactly same you can see here 1 X1 Z M value and N value is again 1 Z X1 Z so M and N both are same
including X and Zed values so the answer will be 1 here so here you can see the Difference because of the normal equality and arithmetic equality now coming to question five question five is find the value of Q for the following snippet given that a is 4 tick B 0 1 01 and Y is 4 tick b 1 1 0 0 here I have taken four bits variables so there are register type variables q a y and then we have to assign Q value uh a or Y so here simply you have to perform bitwise
or operation between a and Y and yes you will get your answers so quickly Perform the this operation so bitwise or operation you have to apply a is 0 1 0 1 and Y is 1 0 and or operation we have to perform so for starting from LSB side 1 Z the answer will be 1 0 0 the answer will be zero 1 1 the answer will be 1 and 0 1 the answer will be 1 so the final value of Q is 4 TI b 1 1 01 so this is all about the simple
bitwise or operation now talking about question six Question six is output value of C and F in the given snippet so in this snippet you can see I have taken three variables basically your register type variables and these variables are of four bits then three integers D EF so a value is 4 tick B 01 and B value is 4 TI P tri0 1 D is 7 and E is 3 now simply a + b value is assigned to C and F is D / e so quickly solve this question so I hope you got
your answers now we can see A is01 and B is Tri 0 1 When we perform the addition so basically this example is the use of arithmetic operators how you can apply the arithmetic operators on given variables you have to check that so we have to perform the addition so when you will add a and b then you will get the answer 0 1 0 0 starting from LSB side so here 1 one the sum will be zero and the carry will be one so the carry bit one and this one so sum will be
again zero and the carry Will be one so the carry one and z0 so finally the sum will be one only and here this is the so the final value of C is 4 TI B 010 this is the final value of C now F value it will be truncated to two because when you will divide 7 by 3 then you will get something or 2 point something value but f is an integer so we have to consider the integer part only so the final value of f is 2 so I hope you got the
correct answers and you Have enjoyed today's video if you have any doubt then you can post in the comment section and share the video as much as possible so talking about the gate Primitives in very log there are some predefined inbuilt gate Primitives and this gate level modeling is the lowest level of abstraction all logic circuits can be designed by using logic gates so there are two different types of gates in basic Gates there are Endor Gates and buff knot Gates so one by one We will discuss okay so starting from basic gates in and
or Gates one scalar output and multiple scalar inputs are there output of the gate is evaluated as soon as one of the input changes the Andor Gates available in very log are and gate orgate nand gate Norgate exor and exor gate so here you can see the symbols of these Gates different Gates have different symbols and talking about the truth table four different values 0 1 x and Zed and according to the gate You are getting the output since these are very uh basic Gates and generally we are using these Gates so I hope these
truth tables are clear to you first of all you have to write the Primitive name then instance name and then output and input ports so some examples I have written here and gate nand and or so first one is and gate inputs are A and B and output is out so here you can see the syntax and and then instance name which is G1 here and then Output out comma a comma B similarly for nand gate you can write nand G2 and then out comma a comma B so in this manner you can write this
index in this example here you can see how we can write the VAR log code in gate level modeling so in this figure you can see and gate and exort gates are there so for this circuit how should we write the VAR log code module and then module name then we have to specify all the input output ports then all the input ports all the Output ports and then for and gate we have to write and and and then instance name which is and gate here and then output o1 comma i1 comma I2 similarly for
exor gate it is exor then exor gate O2 comma I3 comma I4 and then end module so in this manner we can write the very log code in gate level modeling another example is also here so you can see without giving the instance name also we can write this circuit you can see orgate is there Then and plus not so nand gate is there or plus not which is Norgate and exor plus not which is exor gate for that simply we have to write or and then output and input ports you can skip the instance
name part now we have to study about the buff knot Gates which is the second category of basic Gates it's one scalar input and one or more scalar outputs are there buffer and not not gate you can see the symbol only a difference is the bubble In not gate we have bubble in buffer gate there is no bubble truth tables are there in it the inverted output we will get so here also I have considered four different values 0 1 x and Zed in case of buffer when input is zero output is zero when input
is 1 output is one when input is unknown then output is also unknown and in case of high impedence the output is unknown similarly in case of not gate when input is zero then output is one when input is one then Output is zero for unknown the output is also unknown and for high impedence the output is unknown now in this example you can see how we can write the VAR log code for buffer and not Gates simply you have to write the gate name which is buff and then the instance name and then output
and inputs similarly for not get also not and then the instance name and then output and input so in this manner we can write the VAR log code for buff not Gates now we have to start the buff if notif Gates so these Gates have an additional control signal actually they propagate if the control signal is given otherwise the output will be in high impedence State four different types of buff if notif gates are there buff if 1 buff if zero not if one and not if zero so buff if one means buffer with active
High control signal and buff if Zer means buffer with active low control signal so this buff if one or buff if Zer is nothing but buffer gate only with an additional control signal and this control signal can be active high or active low similarly in case of native one it is a not gate with active High control sign signal and not if zero is a not gate with active low control signal here you can see the truth table for buff if 1 buff if Zer and not if 1 not if zero I hope this is
clear to you and now in this example you can see how can we write the very log code for this Circuit the first gate is a not gate with active High control signal so this buff if one third one is buff if zero and the last one is not if zero so very simple code is there first of all the gate buff if one and then buff gate one which is the instance name you can give any name here and then output and input ports so similarly for not if one not if Zer and buff
if Z you can write the very log code I hope the two categores buff if notif and basic gates are now clear To you if you if you have any doubt you can ask now we have to talk about the gate delays so in very log we can introduce gate delays in the logic circuit so three different types of delays are there Rise delay fall delay and turnoff DeLay So starting from Rise DeLay So In Rise delay the gate output transits from 0 x or Z to 1 mean to say whenever there is a transition
from 0 x or Zed to one then this is called The Rise delay actually the time duration Required for that transition is called The Rise delay similarly in case of fall delay the transition is from 1 X or Z to zero so that duration is called the fall delay now in case of turnoff delay Whenever there is a transition in Gate output to high impedance value from any other logic value mean to say from any other logic value that is 0 1 and X there is a transition to zed value that delay is called the
turnoff delay one more thing Guys if the gate output transition is to a don't care value then the minimum of the three delay will be considered for example if rise delay fall delay and turnoff delay all these three values are given and the transition is to a don't care value so in that condition we have to consider the minimum delay value here you can see the syntax if a single delay value is given then you have to consider that in your very log code if rise delay and fall delay separate value is given Then you
have to write both the values and if rise delay fall delay and turnoff delay all the values are given then you have to consider all these value while writing the VAR laog code one more thing if in the question no delay value is given then by default you have to consider as a ideal circuit you can say or as a ideal gate you have to consider but if delay value to consider that value while writing the code so in case of single delay value first of all you Have to write the uh gate name then
hash delay value and then instance name and then output and input PS similarly if rise delay and fall delay both are given then you have to write gate name then hash rise value comma fall value then instance name and all the values rise value fall value and turnoff values are given then you have to write the gate name hash and Ina comma turnoff value then instance name and then output and input ports so I hope this syntax is Clear to you you can also understand this by the this example so here andate and orates are
there andate has a five time unit delay and orgate has a 4 time unit DeLay So In This Very LW code you can see I have written and then hash five and then instance name output and input similarly for orgate it is or then hash 4 instance name and then output and input so in this manner you can insert the delay value while writing the very log code now we will consider some more Examples and as we all know in case of half subtractor two inputs are there and two outputs borrow and difference are there
so difference is nothing but a exor b if a and b are inputs and borrow is a bar B so here in this VAR law code you can see first of all I have written module then module name and then borrow difference a comma B then you have to specify input and output ports then I have taken wire W1 actually this wire W1 I have taken to perform the negation of Input a so here you can see exor then the instance name X1 and then difference comma a comma B this is for the exor gate
then for not gate I have written not N1 and then W1 comma of a and then we will send that negated value from the borrow operation so for endgate here the code is and then instance name and then borrow comma W1 comma B end module so this is the VAR log code for half subtractor circuit one more example here in this circuit and or exor gates are There so you can see how can we write the VAR log code for this you have to start from module so module then module name output and input ports
then you have to specify all the input and output ports here I have taken three wires W1 W2 and W3 and then and gate instance name is A1 for exor gate instance name is X1 and orgate and and gate so these are very simple example and I hope today's video is clear to you so starting from the continuous assignment So actually the gate level modeling is the lowest level of abstraction you can use this for small circuits but but when there is a complex circuit in that situation you cannot use the gate level modeling because
it will be very difficult for you when you are representing a complex a large circuit in terms of logic gates so it will be better if you are using data flow modeling mean to say data flow modeling provides a powerful way to implement a Design so in data flow modeling there is a continuous assignment and continuous assignment is used to derive a value onto a net in data type video I have already explained that in a net data type you cannot store a value it is a continuously driven thing as soon as there is a
change in the input it will reflect to the output net so a continuous assignment replaces gates in a description of the circuit and describes the circuit at a higher level Of abstraction so in continuous assignment we use the keyword assign so talking about the characteristics the left hand sides of an assignment must be a net data type and the right hand side can be of reg or net type continuous assignment is always active and delay values can be specified in that assignment in terms of time units so in this example you can see the out
is net type variable and in1 and in2 are R type variables so simply by using assign Statement you can assign the value to out variable simply here I have written assign out equals to in1 and in2 instead of this in one and in expression whatever value you want to assign to the left hand side variable you can write here in the right hand side so another example I have taken here I have written assign and then by using the concatenation operator C out and sum so here C out is a scalar net and sum is
a vector net and then I have assigned the Value a + B+ C in so in this manner you can use this assign statement now we will talk about the implicit continuous assignment so in implicit continuous assignment instead of declaring a net and then writing a continuous assignment on the net varil log provides a shortcut by which a continuous assignment can be placed on a net when it is declared so mean to say instead of writing two lines first declaration and then assignment you can perform both the Tasks in a single line you can see
here in this example in first example it is the regular continuous assignment first I have declared the variable out as a wire type and then I have assigned the value instead of that by using implicit continuous assignment you can directly declare a value and assign an expression to it in a single line only so this is called the implicit continuous assignment also there can be only one implicit declaration assignment per net Why because a net is declared only once so there should be only one implicit declaration assignment I hope you got the meaning now we
will talk about the delays so delay values control the time between the change in a right hand side operant and when the new new value is assigned to a left hand side mean to say with the help of delays we can control the timing at what time we want to calculate the value of right hand side variable and at what time we want to Assign the value to the left hand side variable so basically there are three ways by which we can specify the delays in continuous assignment statement and these are regular assignment delay implicit
continuous assignment delay and net declaration DeLay So starting from regular assignment delay so here in regular assignment delay after the keyword assign you can specify the delay value here I have written has 10 I am taking 10 time units delay and then I'm Assigning in one and in two this expression I'm assigning to out variable so as soon as there is a change in the right hand side variable that value will be calculated and the final value that is the calculated value will be assigned to the left hand side variable which is out here after
the 10 time units delay in this wave form you can see at 20 time units in1 and in2 signals are changing and whatever we are getting after performing in1 and in two operation that Value will be assigned to out after 10 time units delay that is at 30 time units the value is assigned so this is the meaning of the regular assignment delay one more thing guys an input pulse that is shorter than the delay of the assignment statement does not propagate to the output mean to say here you can see in the in1 there
is a change in the in1 from 80 to 85 but the width is five which is less than the time delay which is 10 so that value will not be Reflected in the out signal and this is called the inertial delay so in inertial delay if there is a change in the input signal but that change is for less than the uh delay time then that value will not be reflected in the output signal and that is called the inertial delay then we will see the implicit continuous assignment DeLay So what is this delay implicit
continuous assignment we have already seen in single line we can Perform both the things declaration assignment here you can specify the delay values as well in this example you can see VRE and then I have written H 10 which is the delay here and then I'm assigning in1 and in two to this left hand side variable out so in this manner you can specify the delay in implicit continuous assignment and this delay is called implicit continuous assignment delay I hope it is clear to you now we will discuss the net declaration delay DeLay So a
delay can be specified on a net when it is declared without putting a continuous assignment on the net mean to say when we are declaring a net at that time only we can specify the delay value and that is called the net declaration delay so here in this example you can see I am declaring a net variable which is out and while declaring it I'm specifying the delay value which is 10 time unit here and then I'm assigning the value in one and In two to this out variable so in this manner you can assign
this net declaration DeLay So finally we have completed today's topic and now we will discuss few examples and with the help of these examples you can clear today's topic so first example I have taken four bit full adder so as we all know in four bit full adder three inputs are there and two outputs sum and carry are there so here in this very log code first of all you have to write module then module Name and then all the input output ports after that you have to declare IO ports which ports are output and
which ports are input you have to declare that and then you have to specify the function of full header so here I have written assign and then by using concatenation operator C out comma sum and then I'm assigning the value A + B plus C in so in this manner you can write a verog code for a 4bit full adder circuit so here you can see guys if you are using a Data flow modeling so your code will be very simple and very short that's why it is preferred for any complex circuit here in this
second example I have taken a 2 to4 line decoder I have written a very L code by using data flow modeling so in 2 to four line decoder as we all know two inputs are there and four output lines are there so as we all know in 224 line decoder two input lines are there and four output lines are there one enable signal is also there it may Be of active high or active low type so A and B are two input lines and D is output Line This D is a 4 bit vector and
E is enable signal which is active low here so here I have assigned the value to d of0 d of 1 D of2 and D of3 so in this manner you can write the VAR log code by using data flow modeling so two ways I have represented in first one I have written assign keyword for all the four lines instead of that you can write single assign keyword and then you have To assign the values which are comma separated so both the ways are correct you can use anyone so start with structured procedure so verilog
supports two structured procedure statement always and initial so all behavioral statements are written inside these blocks these block runs in parallel manner mean to say these blocks are nothing but concurent in nature and their activity starts at zero simulation time one more thing these blocks cannot Be nested mean to say nesting is not allowed inside one always block can there cannot be any other always block also inside One initial statement there cannot be any another initial statement so start with initial statement so this initial statement is once executable mean to say it will executed one
time only and the execution starts at zero simulation time this execution stops when the last statement is executed in case of multiple initial statement Parallel execution is there mean to say all initial statement will be executed parallely and if there are multiple statement inside an initial Block in that condition we need to use begin end state so here you can see in this example I have written module stimulus then I have defined some variables after that I have used multiple initial blocks inside this very log code so in first initial block since only one statement
is there so no need to use any begin end Statement but in second initial block I have defined multiple statement so in this condition we need to use this begin end block also similarly in third initial block also I have used this begin end because multiple statements are there and finally in this initial statement only one statement is defined so no need to use begin end so in this manner you can use initial Block in your very log code and here is the simulation result so you can check now we will see The always statement
so this always statement repeats continuously throughout the simulation time duration since the initial block is concurrent in nature this always statement is also starts at zero simulation time and in case of multiple always blocks parallel execution is there mean to say if there are multiple always block so all the always block will be executed parallell and there can be a deadlock condition also if there is no control for the Simulation time so we need to use this always statement wisely we need to give some condition we need to give some sensitivity list so here is
the example how you can use this always statement in your very log code so here I have used both initial and always blog in the very log code so simply I have written always and then has 10 clock equals to negation of clock since here I haven't defined any particular condition for this always so this clock Will be neged after all 10 time units until this dollar finish will occur so in this manner we can use this always Block in our very LW code now we will start the procedural assignment so procedural assignments update value
of reg integer real or time variables mean to say once the variable values are updated it will not beang changed until and unless another procedural assignment updates the variable with different value also these procedural assignment Are different than the continuous assignment so there are mainly two types of procedural assignment blocking assignment and non-blocking assignment so blocking assignment is represented by the sign equals to these statements are executed sequentially mean to say the statements will be executed in the order they are specified one statement blocks the execution of another statement until it is executed mean to
say the next Statement will be executed If the previous statement will be executed completely then only the next execution will happen also in case of blocking assignment delays value will be added and the reason is the execution H happens in the given order mean to say say in whatever order we have defined this statement in that order only the execution happens so here the delays value will be added also blocking assignment can be used in both Procedural and continuous assignment so here you can see the example inside this initial I have used this B end
and then multiple statements are defined here so here I have used the blocking assignment XY Z I am assigning some value then to count variable I am assigning zero value then this reg a reg B value and then after some time delay I am assigning the value so in this manner you can use the blocking assignment now coming to the non-blocking assignment so it is Represented by sign less than equal to these statements are executed concurrently mean to say the right hand sides are evaluated first and then it is specified assignments are scheduled these non-blocking
assignment can't be used in continuous assignment statement or in a net declaration here you can see the example inside this initial block I have used this beginning and then multiple statements are written here I have used both blocking and non-blocking Assignment but it is always recommended not to mix these blocking and non-blocking assignment always try to use one assignment at a time so now we will talk about delays in procedural assignment so guys in data flow modeling video I have talked about the delay values but that delay values are specific for the continuous assignment and
now I'm going to talk about the delays in procedural assignment so don't mix these two types of delays and don't Get confused so for procedural assignment two types of delays are there regular delay and inra assignment DeLay So starting with the Reg DeLay So if delay value is specified then at that time the entire statement is executed and assigned to the left hand side mean to say this is the delay before the right hand side variable is evaluated and assigned to the left hand side so the entire operation will be delayed in case of regular
delay so here you can See the example here in this initial block I have written xal to 0 without without any time delay and then has 10 y = to 1 so here this one value will be assigned to variable y after this 10 time units DeLay So This is the meaning of the regular delay also in this line you can see here I have written #y x = x + 1 so this x + 1 value will be assigned to this x variable after y time units DeLay So I hope this regular delay is
now clear to you Now we can see this intra assignment DeLay So intra assignment delay is nothing but the right hand side of the equation is evaluated at current time but the value is assigned to the left hand side variable after the delay time this inra assignment delay can be used in both blocking and non-blocking assignment so here in this example you can see in this line Y = to # 5 x + z so this x + z value will be evaluated at current simulation time which is nothing But zero time and this X+
Z value will be assigned to the left hand side variable y after 10 time units so this is the meaning of intra assignment delay I hope it is clear to you now we can see the block statement so two types of block statements are there sequence block and parallel block sequence block are nothing but B end block which is you used to group multiple statements these statements are executed in order they are mentioned means in whatever order we Have written the statements in that order only the simulation will be happen and the delay is treated
relative to the simulation time and the previous statement however in case of fog join it is used to group multiple statement but the statements are executed in concurent Manner and here here the delay is treated relative to the simulation time of the entering the block mean to say at what time we are entering to the block that value will be considered for the Delay so here you can see the example for the sequence block so here I have used beginning inside this initial block and the blocking assignment I have used this is without any delay
time in this initial block you can see I have given some delay time so this xals to one b the Z value will be assigned to X variable at zero time units then # 5 y = to 1 take B1 so this one value will be assigned to variable y after five time units then has 10 Z = to X comma y now Since we have used this begin end so the delay values will be added so this execution will be happened at five time units this simulation will be happened at 5 + 10 that
is at 15 time units and this simulation will be happen at 5 + 10 + 20 that is at 35 time units so this is the meaning of the sequence block begin end now you can see the parallel block that is f join so inside that folk join statements will be executed concurrently mean to say here the delay values will Not be added so the first statement will be executed at zero time unit this statement will be executed at five time units this line will be executed at 10 time units and finally this line will
be executed at 20 time units so here you can see inside this FK join the delay values will not be added it is with respect to the simulation time when we are entering to the block now we will see the conditional statement if Els so here the keyword if Els are used it is The decision maker statement and if we are using multiple statement inside this Ifill statement then we need to enclose it with begin end block also we can use the nested if else if statement so here we can see the syntax so basically
we have three different types in type one we are only using this if so if and then the expression if the given expression is true then the statement will be executed in type two we are using both if and else if then the given expression If this expression is true then this statement will be executed otherwise the given statement will be executed this is the if else and then we can use the nested if else if which is nothing but if and then the given expression if this expression is true then this statement will be
executed else if if the next expression is true then the next statement will be executed else F if this expression is true then this expression will be executed and finally Else default statement if all these expression are not true then finally this else value that is this default statement will be executed so this is the meaning of if else conditional statement now we will talk about the multi-way branching that is case statement so sometimes we cannot use this Ifill statement for our very log code so that time we can prefer the case statement and if
there are multiple statements then we need to use the begin End block so here you can see the syntax I have written case and then the given expression the expression on which we are applying the case statement then we have to write the different different condition of this expression first condition second third and fourth accordingly whatever statement we want to execute we have to write that at last we have to write the default expression this is the default statement if all these expressions are not true then this Default value that is this default statement will
be executed and then end case so in this manner we can use this case statement in our very log code and now we will talk about the last topic of today's video which is looping construct so there are four types of looping statement in verilog for Loop while loop repeat and forever so these looping constructs are very similar to the C programming language these looping statement ments are used inside an Initial or always block and these looping statements can have the delay values as well so one by one we will understand so starting from while
loop so in the while loop the syntax is while and then in parenthesis we have to write the expression so the meaning of while loop is that the while statement executes until the V expression is false and multiple statements are grouped in begin end this V Loop is non- synthesizable in nature so here in this Example you can see I have written initial then in beginning first of all I'm assigning the zero to the count variable and then while and the expression is count is less than 128 after that the statements are written since multiple
statements are there so I have used the begin end block so the meaning of this file Loop is that the given statements will be executed until this expression becomes false till then the statements will be executed so This is about the while loop now we will talk about the for Loop so generally this for Loop consist three parts initialization termination and then increment or decrement this for Loop provides a more compact Loop structure than while loop so here in the syntax you can see for and then first of all the initialization then termination and then
increment or decrement so here I'm incrementing the value with one and then I have written the statement so this is About the for Loop now we will see the repeat Loop so this repeat Loop it rates for a fixed number of times and there will not be any expression required for this Loop repeat Loop must contain a number and this number is equal to how many number of times we want to repeat the given expression this is the meaning of repeat Loop so here in syntax you can see I have written initial inside this beginning
block I have written clock equals to0 and then repeat 128 and then I have written the statements inside this Bend block so the meaning of this repeat block is that this repeat Loop will be executed 128 times and then it will be ended so this is the repeat Loop and then the forever Loop so forever loop mean to say it executes forever till dollar finish or disable statement is encountered forever Loop also does not require any expression so here you can see the syntax inside this initial block I have written begin end and then Clock
equals to one B 0 and then forever has 10 clock equals to negation of clock so forever this clock value will be negated after 10 time units until and unless any dollar finish or disable statement will be encountered so this is the meaning of forever Loop so today's topic is now completed and we will see some examples so that today's video will be more clear to you so the first example is 4 cross one multiplexer so here I have used the behavioral modeling To write the very log code for 4 cross one marks and I
have used the case statement so here you can see I have written module then module name and then input and output ports then the declaration after that I have written this always statement so always at and then this is the sensitivity list so here we have different ways to write the sensitivity list either we can write in this manner S1 or s0 or i0 or it can be comma separated as well mean to say we Can write it as S1 comma s0 comma i0 comma i1 in this manner or simply you can use one estri
sign here so by default it will consider all these variables so we have different different ways to write this so inside this initial all Block in begin end I have written the case statement so case and then S1 comma s0 so in these two variables I'm applying the case statement so the two bit values could be 0 0 0 1 1 0 or 1 1 on different Different condition different different statements will be executed by default I have given the the value out equals to one t BX mean to say if the value of S1
s0 is 0 0 then i0 will be assigned to out in case of 01 i1 value will be assigned to out in case of 1 Z this out I2 value will be assigned to out and in case of 1 one this I3 value will be assigned to out and by default if all these conditions are not true then the unknown value will be assigned to out Then end case end and end module so in this manner you can write the VAR loog code for 4 cross one multiplexer by using behavioral modeling another example here I
have written the VAR log code for 4bit counter so here you can see I have written module then module name input output ports then the port declaration after that always add pause Edge clear or neg clock now here the meaning is these clear and clock signals are not Synchronize if I'm writing only always at posage clear or always at neg clock at that time these two signals are synchronized so here inside this beginning block I have written if clear so if this clear signal is high then the zero value will be assigned to Q else
Q + 1 modul 16 will be assigned to Q now here I have used this modul 16 because it is 4 bit counter so it will count from 0 to 15 and after 15 it will again reach to zero so that's why here we have Used this module 16 module of 16 operation end and then end module so in this manner you can write the VAR log code for 4bit counter so our first topic is system task so there are some task and function which is used to generate the input and output during the simulation
and it is represented by the dollar sign so the first category is internal variable monitoring system task in that we have dollar display dollar monitor Dollar Ride dollar strobe so Talking about the dollar display and dollar right so both the system task are used to print the messages but the difference is dollar display automatically adds a new line character to the end of its output however this dollar right don't add any new line character both dollar display and dollar right represents the current variable current current value of the variables talking about the dollar strobe so
it displays the simulation data at a Selected time that is at the end of the current simulation time when all the simulation events that have occurred for the simulation time and the dollar monitor is mainly used for the monitoring purpose each time a variable or an expression in the argument list changes the value the entire argument list is displayed at the the end of the time step so for this purpose we use the dollar monitor here you can see the syntax all this dollar display Dollar Ride dollar strob dollar monitor same syntax is there in
this double quotes you have to write the string format and then after comma you have to write the parameters which you want to print so we can understand it with the help of example so in this example you can see I have taken this new reg variable which is which is of reg type and then in this initial block first first of all I have given this value one tick B1 to this variable new reg and then I have given The command dollar strobe dollar display and dollar right and this new regge value is also
changed to zero so here you can see the format in double quotes you have to write the string format and then after comma you have to write the parameter value which you want to display so let's see the simulation result so here we'll get for this strobe the value is zero why because see this dollar strobe is nothing but it dis place the value at the end of the Current simulation time so this new reg value earlier it is one but finally its value is changed to zero so this dollar stob represent the final value
which is zero then this dollar display represents the current value only so in this dollar display you will get this value one because it represent this current value not the final value and this dollar monitor since Whenever there is any change in the value of variable it will print that value so earlier it was one And then it is changed to zero so both the values will be printed in this dollar monitor command so here you can see first first it was one and then it is changed to zero so in this manner you can
use dollar strobe dollar display dollar Monitor and dollar right in your verog code while writing this test bench here you can see the dollar random so dollar random provides a mechanism for generating the random numbers it returns a new 32-bit random numbers each time it Is called so the random number is assigned integer it can be positive or negative seed parameter controls the number that dollar random returns so it is mainly used for the stimulus then see the second category which is simulation control task so here we have dollar reset Dollar Stop and dollar finish
dollar reset is used to reset the simulation process that is it Returns the simulation back to zero time Dollar Stop is used to suspend the simulation And dollar finish is used to terminate the simulation so what is the difference between this Dollar Stop and dollar finish Dollar Stop suspends the simulation mean to say you can again start your simulation after some time but this dollar finish terminates the simulation mean to say you cannot resume your simulation once you will give that dollar finish so this is the basic difference now we will talk about the third
category which is simulation time Related task here we have dollar time Dollar s time and dollar real time so this dollar time represent the current simulation time as a 64bit integer dollar s time returns current simulation time as a 32-bit integer and this dollar real time Returns the current simulation time as a real number so you can understand these things with the help of this example so here you can see I have taken two examples in this example in this initial block I have given a value With this time delay 1.55 AAL to 0 then
again HH 1.55 a = to 1 and then at hash $50 stop I'm giving this in this always block I have given hash 50 clock equals to negation of clock so the initial value of clock was zero and then we are changing this value don't worry about the stick time scale it is a compiler directive this 10 nond is the time unit and this one nond is the time precision and just forget about this logic this is nothing but a data type in system very Log and here in this initial block I have taken this
dollar monitor so here I want to print this time value for this I have taken dollar time then clock and then a value so let's see the simulation result so first of all this time was Zero clock was zero and the initial value of variable a was unknown then it was 1.55 but we are giving this dollar time so dollar time will consider the integer value only it will not consider any real number so this 1.55 will be Considered as two so this 2 into time Unit 10 so it will be 20 nond so at
time 20 the clock value will be zero only and the variable a will be zero then at time 30 30 is what 1.55 + 1.55 so it will consider as 30 so this 3 into 10 that will be 30 so at 30 clock will be zero a will be 1 and finally after 50 we are just stopping we are giving this Dollar Stop command but at hh50 we are just negating the clock value so here you can see at time 500 we are getting clock Equals to 1 because clock has negated at 50 time unit
delay and a value is one so here in the second example you can see only the difference is here I have taken dollar real time instead of dollar time so the difference will be in the simulation result it will consider these real time values so initially time was Zero clock was zero and a was unknown then this 1.55 will be considered as 1.6 because the Precision was 1 nond only so 1.6 into this 10 time unit so it will be 16 only so at time equals to 16 clock is 0 a is zero then 1
1.55 + 1.55 so it will be considered as 3.2 so 3.2 into 10 so it will be 32 so at time equals to 32 clock was 0er a equal to 1 here we have given 1 and then at 50 it will be 50 into 10 which is 500 clock has negated and a value is one so in this manner you can use dollar monitor Dollar Stop dollar time Dollar real time tick time scale compiler directive while writing the test benches now we will talk about The compiler directive so a compiler directive may be used to
control the compilation of the verog description we use this tick mark whenever we use the compiler directive so in this video we mainly discuss these three compiler directives tick Define tick include and tick time scale so talking about this tick Define it creates a macro for the next substitution it can be used both inside and outside the module definition and can be used in The Source Description by using this tick character and followed by the macro name so here you can see in this example take Define size 8 so this size is macro and here
I'm giving the value and then while writing the code I am using this macro only tick size I'm not using this value of this size so the benefit of using the tick Define is that you can change your VAR log code just by changing this single line whenever you want to change the uh value of this size macro just you Need to change this one instead of eight you can write 16 32 or 48 and rest of the code will be in terms of this SI macro only so you need to change only single line
and your entire code will be changed so this is the benefit of using tick Define now we will talk about the tick include so this tick include is used to insert the entire content of a source file to another file during the compilation it is used to include Global or commonly used definitions and task so Here you can see you can write this stick include and then in double codes the name of the file from which you want to just insert the content you have to write the name of that file here so in this
manner you can use stick include compiler directive in your VAR log code at last we will talk about the stick time scale as you have already seen in the previous example we have used the stick time scale to define the time precision and the time unit so in this Manner you can Define tick time scale and then this is the time unit SL time Precision so whenever you are writing a test bench you should Define this sck time scale compiler directive otherwise the default value will be considered so verilog provides task and functions to break
up large behavioral designs into smaller pieces task and functions allows the designer to abstract very log code that is used at many places in the design so basically it provides the Reusability task and functions are like sub routines we can define a particular functionality using either functions or call and then we can call these functionalities from anywhere anytime so it is something like sub routine and we need not to write the code again and again if we perform a particular operation we can define a task or function for that and whenever we need that operation
we just call that function or that task this is the Advantage of using task and functions and these task and functions are very important part of very log code and if you are just learning very log and if you are just practicing writing the codes then try to use this task and functions in your code that will increase the readability of your code and your code will be reusable also it looks very uh clean you know because again and again you are not writing the same thing you are just calling so it Will increase the
readability and yes your code will look more clean so first we will see the task what is Task let's see so the tasks are declared with the keyword task and end task and task can enable other task and functions it may executes in nonzero simulation time and it includes delay timing or timing control statements task may also have zero or more arguments of type input output or inout also this task do not returns any value but it can pass Multiple values through output and inout arguments so here you can see the syntax and examples so
the syntax is very simple you can see I have written here task and then the name of that task you have to write whatever name you have to given you can write here then all the input output and in outport list you have to write and then inside this begin end block you have to write the statements and then the inex task so this is the simple syntax of the task Now we will see some examples so here I have taken the task sum so sum is the name of this task task sum and then
you have to write the input and output ports A and B are 8 Bits input and C is a 8bit output then inside this Bend block I have written C = to a + b and then end task so in this manner you can write your task and if you have to just call that task so how you can call that here is the way how you can call it so initial and inside this beginning block I have written reg and then 8 bit variables XY Z and then I have called that sum task sum
and then the arguments XY Z so here these arguments XY Z will be considered in the same order of that AB BC so X and Y will nothing but a and b and Zed will be C so here you will get Z equals to x + y so in this manner you can write a task and then you can call it by giving different arguments we will see some more examples so first example here I have taken a simple task and here I have written module then simple task then task convert so this convert is
a name of that task and the simple task is the module name here so convert is the task name and then I have written here input and output Port so temp in is the 8bit input and temp out is the 8bit output and then inside this begin end I have written the statement temp out and then whatever value we have to give to this we have to give to this temp out I have written this and then the in task So in this manner you can Define your task also you can write your task using
Global variables so what is This Global variable actually while writing the task if you are defining the variable inside that task then that is known as the local variables and those variables are limited to that task only you cannot use those local variables outside the task but you can derive the global variables inside the task and Global variables are nothing but the variables which you are Defining outside the task so here you can see I have defined two variables temp in and temp out since these variables are defined outside the task so it will be
considered as Global variables and you can use these Global variables inside your task so inside this task I have written inside this Bend block T out and then 9x5 into tempin + 32 so in this manner you can use Global variables in your task and here you can see how you can call a task After writing so simple code I have written here module and then task calling this is the module name and then I have written all the ports temp a temp B temp c and temp D I have just defined the ports input
ports and output ports and then I have included one file which is my task. V this is a file where I have defined the task this is the file name and then here I have taken two always Block in one always block I have given temp a in sensitivity list and in Another always I have given temp c in the sensitivity list and then I have called the convert task so here you can see convert and then temp a comma temp B so this temp a will act as an input and the stamp B will
act as an output also here the stamp c will act as an input and the stamp D will act as an output actually these arguments depends on the format of your task how you have written there all the variables all those ports these arguments depends on that so in This manner you can call your task so I hope task is now clear to you I have few more points to tell about the task task can use both blocking and non-blocking assignments and task can be disabled using a disable keyword there are keywords enable and disable
so you can disable a task by using these keywords we will see uh these things in more detail in our practice set when I'll give some different different quotes that time uh these things will be more Clear also task may have zero or many arguments and doesn't return any value as I have already told task never returns any value function returns a value so now we will see functions what is function functions are declared with the keyword function and end function functions can enable other functions but not other tasks functions always execute in zero simulation
time mean to say we cannot include delay timing or timing control statement inside a function Sometimes a question is asked like find the error and they just Define they just write a function and inside that function somewhere they have just defined a time delay so whenever you see a time delay or any timing control statement inside a function that means there is an error because we cannot Define any delay value or any timing control statement inside the function so the small small question will ask in your exam or in your interviews find the Error kind
of things so also function must have at least one input argument and it returns a single value they cannot have output or inout arguments so these are few of the things about the functions now we will see the syntax of the function it is very simple function and then automatic return type then the name and then the port list here automatic is the optional thing if you are writing the automatic function that time you need to write this keyword Otherwise if it is static function no need to write this keyword simply write function and then
the name of your function and then the port list inside the beginning block you can write your statements and then the end function this is the simple syntax here I have given this example I have written function and then 7 down to0 sum this 7 down to0 that is 8 Bits are nothing but the width of the sum and then I have taken input 7 down to 0 a comma B here I Have taken two inputs and then inside this beginning sum equals to A + B so this function is giving a return value A
+ B so if V are passing two values A and B inside this function sum so finally it will return a sum of of these two values and then end function so this is the meaning of function it will return at least a value that means a sing not at least it returns single value only this is the concept of function here we will see some more examples first I have Taken a simple function so here I have written module and then the simple function then function and the name of the function which is my
function then input AB c d inside this beginning block I have written my function and then a plus B plus C minus D whatever value you want to give to this my function you can write here and then the end function so in this manner you can Define your function and now it's time to call this function how you can call this let's see Here module and then the function calling this is the module name and these are the arguments here here I have taken input a b CDE e and then the output F I'm
including this file my function. V actually this my function. V function file is nothing but the file where I have written the function which I'm going to call that file you need to include and here I'm writing assign F and then my function my function is nothing but the name of this function And you are calling that function here so my function and then the arguments A B C D and whatever you want to just assign you can write here and then the end module so in this manner you can Define your function and you
can call your function I hope it is clear to you now we will talk about the difference between the task and functions task can call any number of functions or task within itself but in case of functions it can call any number of functions only Not any task so task can call both function and task but functions can call other functions only not other tasks task cannot return any value when it is called instead the task can have output arguments however in case of function it returns a single value when it is called in system
VAR log the return value can be optionally voided actually in system VAR log we can use automatic task and functions and that time it provides some functionality and some fun some Flexibility so we will discuss those things in system VAR log videos so these are the difference between the task and function also task and functions both are synthesizable constructs functions are mainly used in combinational logic however the task can be used used in both synchronous and combinational logic here I have given a difference between the automatic that is reentrant Task and the static task this
automatic task is a part of uh system very L we mostly use There only but here for your knowledge I have just given this difference so whenever you see this keyword automatic don't be confused you can use automatic task or automatic functions it will just provide some flexibilities in case of automatic task there is dynamic allocation of memory however in case of static task there is static allocation so these are few differences between the automatic task and static task we will discuss in detail in system very log Videos so uh first of all I have
written here two different formats yes two formats one for the combinational circuit and one for the sequential circuit so this is the first format whenever you have a very uh simple very LW code for any combinational circuit then you should form follow this pattern actually this pattern is very much simple and if you are using this pattern while writing the test bench then uh you will not skip any command like Initialization or the variation or that dollar monitor or dollar finish so you will not be uh confused that time which thing you should write first
and which command you should use so that's why I'm suggesting you to follow this pattern because I personally follow these patterns always always I follow these pattern patterns and you should also follow because once you started following these things you will feel very confident very much confident I'm Sure the benefit of using these formats are uh your code will look very neat and clean uh commands will not be skipped that time while writing the test bench and so first we will see this first format so here module and then test bench name whatever name you
have to give you can give there and then input declaration output declaration then Duty instantiation after that you have to use three initial blocks first second and third in first initial block you have to Initialize your variables in second initial block you have to vary those variables uh you can give a fixed value some uh set of values you can provide to input variables or you can use some Loops here for Loop or repeat these types of loop you can use and then in third initial block you have to use dollar monitor and dollar finish
command along with that if you are using Eda playground then dollar dump files and dollar dump VES these two commands you Can use here in the third initial block so you can see if you are uh following this pattern then nothing will be skipped and you are writing in a in a very proper format first initialization then variation then you have to monitor all those values if you are writing test bench for a sequential circuit then CL clock generation part is should be there so take one more initial block for clock generation so this format
is for sequential circuit test bench so module Then test name after that input declaration output declaration Duty in sensation after that take first initial block for clock generation second initial block for initialization third initial block for variation of the U input variables and then in last initial block you have to give dollar monitor dollar finish in case of playground you can give dollar dump files and dollar dump fs and then end modu so I hope these two formats are now clear to you And uh we will see some examples in today's video and through that
uh through those examples I will explain how you can write the test benches so this is the first example I have taken full Eder very LW code this code is very simple and I hope this code is clear to all the students so I'm not going to explain this so simply here I have taken sum and carry two outputs and a b c in three inputs some the value is assigned a exor b exor c in and to carry we are Assigning A and B B and C C and A so now we will see
how we can write the Test match so there are two different ways by which we can write the test bench for full add circuit first one is you can give some set of values to the input variables and then you can check whether your uh circuit is working properly or not actually the thing is what is the need of writing the test bench why one should write the test bench just to test whether your design is working correctly Or not through the test bench you can check whatever design uh you are written whatever code you
have written that is working correctly or not so basically it is used to test your design so we need to give different different input values and whatever output is generated by which we can check whether the circuit is working correctly or not so here simply I have written module and then the test name then re type input Y type output then it is Duty instantiation Here uh make sure this order should be same as that of the code so here I have given this order Su carry AB BC in so while instantiating that you need
to give the same order then in first initial block I have initialized all the variables in second initial block I have given some set of values a 1 B 0 C in then A1 B1 C in Zer like that only I have given some set of values with time delays and then in third initial block I have given dollar Monitor and dollar Finish now again dollar monitor I have explained in very much detail in compiler directive video so if you have not watched that video then please watch that and clear the concept of compiler directives
because those compiler directives are used in test bench so here in dollar monitor first we have written this dollar time try to use this dollar time because uh whenever you will check your terminal so uh in case of this dollar time you will get at what Simulation time you are getting what output so try to use this dollar time then here we are we have given the values a b c in then some carry and here we have given person B because we need to print the values in binary format and then dollar finish end
module so in this manner we can write the test bench for the full adder circuit this is the first way another way is that uh you can use the loop uh instead of giving some set of values so again same thing module Then test name and then re type input by type output only the difference is here we have taken integer I why this integer just for this for Loop that's why we have taken that integer then here we have done the instantiation part then in first initial block initialization is done in second initial block
we have applied a for Loop so in this for loop I is varying from 1 to 8 and it is incremented it is less than 8 actually so 1 to 7 it will vary and then It will be incremented by one then this I value will be assigned to a b and c in and after each value we have given this 10 time unit delay and then in third initial block we have given dollar Monitor and dollar finish so this is the another way by which you can write the test bench for full add circuit
I hope both the ways are now clear to you and it's better to use Loops instead of giving some diff uh set of values to the input variables then the second example Is JK flipflop very LW code uh most of the students were asking how we can write the test bench or how we can write the vog code for JK flipflop and some flipflop conversion questions so that's why I have taken this example so uh here I have written module and then JK flip flop this is the module name and then Q QB J K
and clock then input is J K clock and reg type output q and another output QB then I have taken some parameters hold reset set and toggle for hold it is 00 011011 without parameter also you can write the code it is completely your choice then assign QB equals to negation of Q then in in uh this always block always at pause clock we have applied case statement case J comma K now we are applying the case statement in this J and K variable so in case of hold we have to assign Q to the
output Q in case of reset we have to assign zero to this Q now hold means what JK value should be 0 0 in case of reset JK value is 0 1 in case of set it is 1 Z and in case of toggle it is 1 one so in case of toggle we are assigning negation of Q to that output q and then end case and module so in this manner you can write the Val law code for the JK flip flop now we can see how uh this test bench could be written for
the JK flip flop so module and then JK flipflop TB re type input we have taken y Ty output then the dut instantiation after that JK flipflop is A sequential circuit so we need to generate clock so here in this first initial block I have generated the clock now what is the way how you can generate the clock so first you need to give some value so clock equals to one TI B 0 uh initial value we have given zero then forever hash five clock equals to negation of clock so after each five time units
this clock will be negated it will be toggled so here we have generated the clock then now in second Initial block I have initialized the value so J and K I have given 0 0 to both the variables and then in third initial block block I have given some set of values with time delay 10 time unit and then in third initial block I have given dollar Monitor and dollar finish command one more thing guys what value you are giving here in dollar finish that you have to make sure it should not be less than
the time delay which you are providing here uh it Should be actually more than all the delay values you have given in the third initial block because if you have given uh suppose 60 or 70 time unit delay here total delay I'm talking about and here you have written hash 50 so all set of values will not be applied in that condition and before that your simulation will be finished so make sure this delay for the dollar finish command it should not be less than these time delays then it is the terminal output so You
can check from here whether we are getting correct output or not and don't be confused with these terminal outputs I'm giving just for the understanding purpose now it is your task to write the code and test bench by your own and then test whether you are getting correct output or not this is the third example which is 4bit synchronous loadable binary up down counter so most of the students have doubt how they can write the very log code for the counter Circuit because we have different categories in counters up counter down counter up down counter
then loadable counter uh synchronous counter asynchronous counter different different categories are there so that's why I have chosen this example actually I'm trying to cover most of the topics through these examples so that students can clear their doubt whatever small doubts they have they can clear through these Examples so here I have written module then the module name here P declaration part and then D in which is 4bit input then other in puts are clock reset load and up down and then reg type count output I have taken which is of four bits then in
always at paage clock different different conditions are there what happen if recent if reset is high what happened if load signal is high what happened if this up down is high and what happened if it is low so all The scenarios we have to cover so it's better to use f statement here so here I have written if reset if signal is high then we need to assign zero to this count else if load if load signal is high so that time this D in value will be loaded to this output count if this up
down signal is high so it will perform up counting and if it is low then it will perform the down counting so here I have written if up down then count equals to count + 1 else it is Count equals to count minus one and then end module so in this manner you can write the very law code for up down counter now we can see the test bench here so simply re type input Y type output instantiation then in first initial block clog generation part is there in second initial block I have given some
values here this is basically for the initialization then in third initial block I have given different set of values to reset load and up down and This input D in and then in last initial block dollar Monitor and dollar finish uh one more thing I want to just make it clear whenever you are writing a test bench try to cover all the functionality of your very log code in Advan very log we have a topic called code coverage so in that what we have to check whether the test bench is covering all the functionality of
the code or not how much coverage it is providing and the Meaning is that only how much part is covered in that so whatever functionality is there in your code in your circuit all those things should be covered in the test bch so here it is reset then load then high value of up down and low value of up down so we need to write a test bench which can cover all these scenarios so that should be a perfect way of writing the test bench so here I have given the terminal output so you can
see first of all we just make This reset signal high so the output will be zero that time because the circuit will be reset at that time then I have given load equals to high so if load is high so earlier the value was zero and after giving this load signal High the input this D in input is loaded so here the count value becomes four after that this reset is zero load is zero and we have given this up down signal so if this up down signal is high that time this counter will perform
up Counting operation so you can see here the count is incremented 4 5 6 7 these values are incrementing and if up down is low that time the counter performs down counting so here values are decrementing from 10 2 9 8 7 like that the values are decrementing so here you can see I have covered all the aspect up counting down counting reset and load and in that manner only you need to write a very log Code test match now this is the last example of today's Video which is a d flipflop very log code
so this code is very simple we have taken input D clock reset and BR type output q and another output QB we we are assigning this QB with value negation of Q then in always at PA clock if reset signal is high then we are assigning zero to this Q else input D to this Q so this is a very simple code of flipflop now we will see the test bench writing the special thing is that here I have used task while writing the test bench So uh Whenever there is a complex design or a
bigger circuit that time it's better to use task while writing the test bench it will uh give very uh you know kind of clean look to your code it will be very manageable and you will not be confused which thing you have to write first what is second you need not to be confused there the simple way is that use task while writing the test imch so here I have written module then module name re type input Y type output And then instantiation after that in first initial block we have generated clock then I have
defined a task here the name of this task is initialize so this is the format of writing the task so task then task name then in begin end I have given two values D equal to res equal to0 so this is my task to initialize that means it is performing initialized operation then I have written another task named stimulus and here I have given two parameters I and J Here so whenever you are calling the task you can give argument here okay so here this I value is assigning to D and J value is assigning
to reset and then in third initial block we are simply calling all the task which we have defined so first this initialize what this task will do it will initialize the variables then stimulus uh I am calling the stimulus with argument 1 comma 1 then with 1 comma 0 then 0 comma 0 and 1 comma 0 so in this manner you can give Different different arguments to this task stimulus and then in last initial blog dollar Monitor and dollar finish end module and this is the terminal output you can check whether you are getting correct
output or not so I hope today's video is clear to all the students if you have any any doubt you can tell me in the comment section and I hope you will follow those two formats of writing the test bench one for the combinational circuit and one for the Sequential circuit those formats are very useful if you are a beginner if you have just you are just starting learning of very L code then it is recommended to use these formats it's it's not a hard and fast rule to use that format only but it will
help you a lot you will not getting uh confused while writing the test bench things will be very very much Clear if any other guy is reading your code that time also your code will be very clear very much understanding if You have not join our telegram group till now then join that group and if you have liked today's video then like the video subscribe the channel and share the videos as much as possible so thanks for watching