SlideShare a Scribd company logo
OPERATORS: 
 A set of operators is available in Verilog. The operator symbols are 
similar to those in C language 
 With these operators we can carry out specified operations on the 
operands and assign the results to a net or a vector set of nets as the case 
may be. 
Unary Operators: Unary operators do an operation on a single operand and 
assign the result to the specified net. All unary operators get precedence 
over binary and ternary operators. 
Unary operators and their symbols:
 Reduction operators opearate on all bits of a single operand and produce 1 
–bit result. The operator list given in previous slide 
 For reduction and: if any bit is 0 , the result is 0,else if any bit is an X or Z , 
the result is an X , else the result is 1. 
 Like that apply for or,nand,nor 
 for reduction XOR: if any bit is an X or Z the result is X ,else if there are 
even number of 1’s in the operand, the result is 0,else the result is 1. 
 a= ‘b0110, b= ‘b0100 
 then | b is 1 
 &b is 0 
 ~^ A is 1 
 next example myreg = 4’b01x0 ; 
 then ^myreg is an x
Binary operators: 
 Most operators available are of the binary type. A binary operator takes on 
two operands; the operator comes in between the two operands in the 
assignment. 
x The arithmetic operators treat both the operands as numbers and return the 
result as a number. 
x All net and reg operand values are treated as unsigned numbers. 
x Real and integer operands may be signed quantities. 
 The result of any arithmetic operation — with the “+” or “–” or with any of 
the other arithmetic operators discussed later — will have an x value if any of 
the operand bits has an x or a z value. 
 Classified into arithmetic operators, logical operators, relational operators, 
equality operators, bit wise logical operators, operator truth tables, shift 
operators.
Arithmetic operators: 
The modulus operand is similar to that in C language – It provides 
the remainder of the division of two numbers. 
Example: 
module add_8(a,b,c); 
input[7:0]a,b; 
output[7:0]c; 
assign c = a + b ; // indication of arithmetic binary operator for 
//addition 
endmodule
Examples: 
7/ 4 results 1 // division operation 
 7 % 4 results 3 // modulus operator 
 - 7 % 4 results -3 // modulus operator 
 if any bit of an operand in an arithmetic operation is an x or z , the entire 
result is x for example ‘b10x0 + ‘b01111 is ‘bxxxxx 
 the size of the result of an arithmetic expression is determined by the 
size of the largest operand.
Logical operators: 
 There are two logical operators involving two operands. The operands 
concerned can be variables or expressions involving variables. 
 In both cases the result of the operation is a single bit of value 1 (true) or 0 
(false). 
 If a bit in one of the operands is x or z, the result of evaluation of the 
expression has an x value. 
Crd = ‘b0 , dgs = ‘b1 then 
Crd && dgs is 0 
Crd||dgs is 1 
For vector operands , a non zero vector is treated as a 1, for example 
abus = ‘b0110 , bbus = ,b0100 
Then abus||bbus is 1 also abus&&bbus is also 1
Relational operators: There are four relational operators, their details are 
 A relational operator treats both the operands as binary numbers and 
compares them. 
 The result is a 1 (true) bit or a 0 (false) bit. If a bit in either operand is x 
or z, the result has x (unknown) value. 
 The operands can be variables or expressions involving variables. 
Operands of net or reg type are treated as unsigned numbers. 
Real and integers can be positive or negative (i.e., signed) numbers.
Example of relational operators: 
 23 > 45 is false (value 0), 
 while 52 < 8’hxff is x 
 if operands are not of the same size , the smaller operand is zero filled on 
the MSB side , for example 
‘b1000 >= ‘b01110 
is equivalent to ‘b01000>= ‘b01110 which is false value 0 is the output
Equality operators: 
 The equality operator makes a bit-by-bit comparison of the two operands 
and produces a result bit. 
 The result bit is a 1 (true) if the operand condition is satisfied; otherwise it 
is 0 (false). 
 The operands can be variables or expressions involving variables. 
 If the operands are of unequal length, the shorter one is zero filled to 
match the larger operand. 
 The operators in this category are only of two types – those to test the 
equality and those to test inequality. 
 == (logical equality) 
 != (logical inequality) 
 ===(case equality) 
 !== (case inequality) 
The result is 0 if the comparison is false, else the result is a 1, in case 
comparisons , values x and z are compared strictly as values that is with no 
interpretations.
Equality operators and their symbols:
 Examples of Equality operators: 
Example data = ‘b11x0 ,addr = ‘b11x0 then data = =addr is 
unknown , that is the value x and 
 if data ===addr is true , that is the value 1. 
 If the operands are of unequal lengths , the smaller operand is 
zero filled on the MSB side, that is on the left, for example 
2’b10 == 4’b0010 
is same as 
4’b0010==4’b0010 which is true the result value is 1
Bit wise logical operators: 
 The operator does a specified bit-by-bit operation on the two operands 
and produces a set of result bits. 
 The result is (bit-wise) as wide as the wider operand.If the width of one of 
the operands is less than that of the other, it is bit-extended. by filling zero 
bits and the widths are matched. 
 Subsequently, the specified operation is carried out. 
If one of the operands has an x or z bit in it, the corresponding result bit is 
x. Either operand can be a single variable or an expression involving 
variables.
Operator Truth Table: bit wise operators 
 The truth tables for different types of bit-wise operators are given in Table 
Note that an z input is treated as an x value.
Examples of bitwise operators: 
A= ‘b0110 ,B =‘b0100 then A | B is 0110 , A& B is 0100 
If the operands are unequal in length, the smaller operand is zero filled on 
the most significant side for example 
‘b0110 ^ ‘b10000 
Is same as ‘b00110 ^ ‘b10000 
Answer is ‘b10110
Shift Operators: 
 The << operator executes left shift operation, while the >> operator 
executes the right shift operation. 
In either case the operand specified on the left is shifted by the number of 
bits specified on the right. 
The shifting is done irrespective of whether the bits are 0, 1, x, or z. 
The bits shifted out are lost. 
 The vacated positions created as a result of the shifting are filled with 
zeroes. 
 If the right operand is x or z, the result has an x value. If the right operand 
is negative, the left operand remains unchanged.
Shift Operators contd..: 
 the shift operation shifts left operand by the right 
operand number of times. It is a logical shift .The 
vacated bits are filled with 0 , if the right operand 
evaluates to an x or z, the result of the shift operation 
is an x. 
 reg[0:7] Qreg; 
Qreg= 4’b0111; 
qreg >> 2 is 8’b0000_0001
Ternary Operator: Verilog has only one ternary 
operator – the conditional operator. 
 It checks a condition and does a branching. It is a versatile and powerful 
operator. 
The general form is A?b:c 
 The conditional operation is made up of two operators – “?” and “:” – 
and three operands. 
 The two operands separate the three operators in the order shown. 
 The operational sequence of the operation is as follows: 
“A” is evaluated first. 
If A is true, b is evaluated. 
If A is false, c is evaluated. 
If A evaluates to an ambiguous result, both b and c are evaluated.
Conditional operator contd… 
cond_expr ? expr1:expr2 
 If cond_expr is true (that is ,has a value 1), expr 1 is selected, if cond_expr 
is false (value 0) , expr2 is selected. 
 if cond_expr is an x or a z , the result is a bitwise operation on expr1 and 
expr2 with the following logic: 0 with 0 gives 0, 1 with gives 1, rest are x. 
 here is an example 
 wire [0:2] student = marks >18 ? Grade_A : grade_c; 
 the expression marks > 18 is computed ; if true , Grade_A is assighned to 
student , if marks <=18 , grade_C is assighed to student 
Another example 
always 
#5 ctr = (ctr!=25) ? (ctr+1) : 5; 
 The expression in the procedural assignment says that if ctr is not equal to 
25 increment ctr, else if ctr becomes 25, reset to 5.
Operator priority: 
 A clear understanding of the operator precedence makes room for a 
compact design description. But it may lead to ambiguity and to inadvertent 
errors. 
 Whenever one is not sure of the operator priorities, it is better to resort to 
the use of parentheses and ensure clarity and accuracy of expressions. 
 Further, some synthesizers may not interpret the operator precedence 
properly. These too call for the apt use of parentheses. 
 In any expression, operators associate from left to right. Ternary 
operator is the only exception to this; it associates from right to left.
Examples: 
 P = Q – R + S; 
Here R is subtracted from Q and then S is added to the result. However, 
operator precedence does not cause any ambiguity or change the result 
here. 
 P = Q – R / S; 
In the above case the “divide” operator “/” has precedence over the 
“subtract” operator “–”. Hence R will be divided by S, and the result will be 
subtracted from Q. 
 If division of (Q – R) is desired, 
the expression has to be recast as P = (Q – R) / S; 
 In a lengthier expression such as P = a1 – a2 / a3 + a4 * a5; 
The operation is equivalent to P = a1 – ( a2 / a3 ) + ( a4 * a5 ); 
Use of parentheses adds to clarity especially in operations involving more 
than two operators. 
 The operation P > Q – R is the same as P > (Q – R) 
 since the relational operator “>” has a lower precedence than the 
algebraic operator “–”. 
 Similarly, the expression P + Q <= R is the same as ( P + Q ) <= R.

More Related Content

What's hot

Basic logic gates
Basic logic gatesBasic logic gates
Basic logic gatesKumar
 
Universal gates electronic
Universal gates electronic Universal gates electronic
Universal gates electronic
Sooraj Maurya
 
Boolean Algebra
Boolean AlgebraBoolean Algebra
Boolean Algebragavhays
 
Gray Code.pptx
Gray Code.pptxGray Code.pptx
Gray Code.pptx
Pooja Dixit
 
adder and subtractor
 adder and subtractor adder and subtractor
adder and subtractor
Unsa Shakir
 
Combinational circuits
Combinational circuits Combinational circuits
Combinational circuits
DrSonali Vyas
 
Exact &amp; non exact differential equation
Exact &amp; non exact differential equationExact &amp; non exact differential equation
Exact &amp; non exact differential equation
AlaminMdBabu
 
Half adder & full adder
Half adder & full adderHalf adder & full adder
Half adder & full adder
Gaditek
 
Boolean algebra And Logic Gates
Boolean algebra And Logic GatesBoolean algebra And Logic Gates
Boolean algebra And Logic GatesKumar
 
Operator.ppt
Operator.pptOperator.ppt
Operator.ppt
Darshan Patel
 
Adder & subtractor (Half adder, Full adder, Half subtractor, Full subtractor)
Adder & subtractor (Half adder, Full adder, Half subtractor, Full subtractor)Adder & subtractor (Half adder, Full adder, Half subtractor, Full subtractor)
Adder & subtractor (Half adder, Full adder, Half subtractor, Full subtractor)
ISMT College
 
Logic gates
Logic gatesLogic gates
Logic gates
Rahul Thukral
 
Digital logic gate and its application
Digital logic gate and its applicationDigital logic gate and its application
Digital logic gate and its application
Abdullah Al Masud
 
Bcd to excess 3 code converter
Bcd to excess 3 code converterBcd to excess 3 code converter
Bcd to excess 3 code converter
Ushaswini Chowdary
 
Demultiplexer
DemultiplexerDemultiplexer
DemultiplexerTech_MX
 
Number system in Digital Electronics
Number system in Digital ElectronicsNumber system in Digital Electronics
Number system in Digital Electronics
Janki Shah
 
decoder and encoder
 decoder and encoder decoder and encoder
decoder and encoder
Unsa Shakir
 
Digital Logic Design
Digital Logic Design Digital Logic Design
Digital Logic Design
Vaagdevi College of Engineering
 
BOOLEAN ALGEBRA & LOGIC GATE
BOOLEAN ALGEBRA & LOGIC GATEBOOLEAN ALGEBRA & LOGIC GATE
BOOLEAN ALGEBRA & LOGIC GATE
Ideal Eyes Business College
 

What's hot (20)

Basic logic gates
Basic logic gatesBasic logic gates
Basic logic gates
 
Universal gates electronic
Universal gates electronic Universal gates electronic
Universal gates electronic
 
Boolean Algebra
Boolean AlgebraBoolean Algebra
Boolean Algebra
 
Gray Code.pptx
Gray Code.pptxGray Code.pptx
Gray Code.pptx
 
adder and subtractor
 adder and subtractor adder and subtractor
adder and subtractor
 
Combinational circuits
Combinational circuits Combinational circuits
Combinational circuits
 
Exact &amp; non exact differential equation
Exact &amp; non exact differential equationExact &amp; non exact differential equation
Exact &amp; non exact differential equation
 
Half adder & full adder
Half adder & full adderHalf adder & full adder
Half adder & full adder
 
Boolean algebra And Logic Gates
Boolean algebra And Logic GatesBoolean algebra And Logic Gates
Boolean algebra And Logic Gates
 
Operator.ppt
Operator.pptOperator.ppt
Operator.ppt
 
Adder & subtractor (Half adder, Full adder, Half subtractor, Full subtractor)
Adder & subtractor (Half adder, Full adder, Half subtractor, Full subtractor)Adder & subtractor (Half adder, Full adder, Half subtractor, Full subtractor)
Adder & subtractor (Half adder, Full adder, Half subtractor, Full subtractor)
 
Chap 3
Chap 3Chap 3
Chap 3
 
Logic gates
Logic gatesLogic gates
Logic gates
 
Digital logic gate and its application
Digital logic gate and its applicationDigital logic gate and its application
Digital logic gate and its application
 
Bcd to excess 3 code converter
Bcd to excess 3 code converterBcd to excess 3 code converter
Bcd to excess 3 code converter
 
Demultiplexer
DemultiplexerDemultiplexer
Demultiplexer
 
Number system in Digital Electronics
Number system in Digital ElectronicsNumber system in Digital Electronics
Number system in Digital Electronics
 
decoder and encoder
 decoder and encoder decoder and encoder
decoder and encoder
 
Digital Logic Design
Digital Logic Design Digital Logic Design
Digital Logic Design
 
BOOLEAN ALGEBRA & LOGIC GATE
BOOLEAN ALGEBRA & LOGIC GATEBOOLEAN ALGEBRA & LOGIC GATE
BOOLEAN ALGEBRA & LOGIC GATE
 

Viewers also liked

Logical Operators in Brief with examples
Logical Operators in Brief with examplesLogical Operators in Brief with examples
Logical Operators in Brief with examplesMujtaBa Khan
 
Presentation on Logical Operators
Presentation on Logical OperatorsPresentation on Logical Operators
Presentation on Logical OperatorsSanjeev Budha
 
Introduction to basic programming
Introduction to basic programmingIntroduction to basic programming
Introduction to basic programming
Jordan Delacruz
 
Operators and expressions
Operators and expressionsOperators and expressions
Operators and expressionsvishaljot_kaur
 
Introduction to Microprocessors
Introduction to MicroprocessorsIntroduction to Microprocessors
Introduction to Microprocessors
76 Degree Creative
 
Basic programming
Basic programmingBasic programming
Basic programming
Nicole Danielle Mallari
 
BASIC Programming Language
BASIC Programming LanguageBASIC Programming Language
BASIC Programming Language
Jeff Valerio
 
Fortran 95
Fortran 95Fortran 95
Fortran 95
Zaahir Salam
 
Fortran introduction
Fortran introductionFortran introduction
Fortran introduction
santhosh833
 
Microprocessor ppt
Microprocessor pptMicroprocessor ppt
Microprocessor ppt
swaminath kanhere
 
Computer Hardware and software
Computer Hardware and softwareComputer Hardware and software
Computer Hardware and softwareVisualBee.com
 
Presentation on input devices...
Presentation on input devices... Presentation on input devices...
Presentation on input devices...
simmi khera
 
Computer Generation Presentation
Computer Generation PresentationComputer Generation Presentation
Computer Generation PresentationJayesh Modi
 
Presentation on Input and Output Devices
Presentation on Input and Output DevicesPresentation on Input and Output Devices
Presentation on Input and Output DevicesZobia Aziz
 
GENERATIONS OF COMPUTER
GENERATIONS OF COMPUTERGENERATIONS OF COMPUTER
GENERATIONS OF COMPUTER
Rajat More
 
Lect 1. introduction to programming languages
Lect 1. introduction to programming languagesLect 1. introduction to programming languages
Lect 1. introduction to programming languagesVarun Garg
 
The five generations of computers presentation
The five generations of computers presentationThe five generations of computers presentation
The five generations of computers presentationSwarnima Tiwari
 

Viewers also liked (20)

Logical Operators in Brief with examples
Logical Operators in Brief with examplesLogical Operators in Brief with examples
Logical Operators in Brief with examples
 
Presentation on Logical Operators
Presentation on Logical OperatorsPresentation on Logical Operators
Presentation on Logical Operators
 
Introduction to basic programming
Introduction to basic programmingIntroduction to basic programming
Introduction to basic programming
 
Cobol basics 19-6-2010
Cobol basics 19-6-2010Cobol basics 19-6-2010
Cobol basics 19-6-2010
 
Operators and expressions
Operators and expressionsOperators and expressions
Operators and expressions
 
Introduction to Microprocessors
Introduction to MicroprocessorsIntroduction to Microprocessors
Introduction to Microprocessors
 
Basic programming
Basic programmingBasic programming
Basic programming
 
BASIC Programming Language
BASIC Programming LanguageBASIC Programming Language
BASIC Programming Language
 
Fortran 95
Fortran 95Fortran 95
Fortran 95
 
Fortran introduction
Fortran introductionFortran introduction
Fortran introduction
 
Presentation on output device
Presentation on output devicePresentation on output device
Presentation on output device
 
Microprocessor ppt
Microprocessor pptMicroprocessor ppt
Microprocessor ppt
 
Hardware & Software
Hardware & SoftwareHardware & Software
Hardware & Software
 
Computer Hardware and software
Computer Hardware and softwareComputer Hardware and software
Computer Hardware and software
 
Presentation on input devices...
Presentation on input devices... Presentation on input devices...
Presentation on input devices...
 
Computer Generation Presentation
Computer Generation PresentationComputer Generation Presentation
Computer Generation Presentation
 
Presentation on Input and Output Devices
Presentation on Input and Output DevicesPresentation on Input and Output Devices
Presentation on Input and Output Devices
 
GENERATIONS OF COMPUTER
GENERATIONS OF COMPUTERGENERATIONS OF COMPUTER
GENERATIONS OF COMPUTER
 
Lect 1. introduction to programming languages
Lect 1. introduction to programming languagesLect 1. introduction to programming languages
Lect 1. introduction to programming languages
 
The five generations of computers presentation
The five generations of computers presentationThe five generations of computers presentation
The five generations of computers presentation
 

Similar to Operators

Types of Operators in C
Types of Operators in CTypes of Operators in C
Types of Operators in C
Thesis Scientist Private Limited
 
Opeartor &amp; expression
Opeartor &amp; expressionOpeartor &amp; expression
Opeartor &amp; expression
V.V.Vanniapermal College for Women
 
4_A1208223655_21789_2_2018_04. Operators.ppt
4_A1208223655_21789_2_2018_04. Operators.ppt4_A1208223655_21789_2_2018_04. Operators.ppt
4_A1208223655_21789_2_2018_04. Operators.ppt
RithwikRanjan
 
Operators in Python
Operators in PythonOperators in Python
Operators in Python
Anusuya123
 
Unit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in cUnit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in c
Sowmya Jyothi
 
python operators.ppt
python operators.pptpython operators.ppt
python operators.ppt
ErnieAcuna
 
Java basic operators
Java basic operatorsJava basic operators
Java basic operators
Emmanuel Alimpolos
 
Operators used in vb.net
Operators used in vb.netOperators used in vb.net
Operators used in vb.net
Jaya Kumari
 
Operators and it's type
Operators and it's type Operators and it's type
Operators and it's type
Asheesh kushwaha
 
C++ Expressions Notes
C++ Expressions NotesC++ Expressions Notes
C++ Expressions Notes
Prof Ansari
 
itft-Operators in java
itft-Operators in javaitft-Operators in java
itft-Operators in java
Atul Sehdev
 
Cprogrammingoperator
CprogrammingoperatorCprogrammingoperator
Cprogrammingoperator
teach4uin
 
Py-Slides-2.ppt
Py-Slides-2.pptPy-Slides-2.ppt
Py-Slides-2.ppt
AllanGuevarra1
 
Py-Slides-2 (1).ppt
Py-Slides-2 (1).pptPy-Slides-2 (1).ppt
Py-Slides-2 (1).ppt
KalaiVani395886
 
Py-Slides-2.ppt
Py-Slides-2.pptPy-Slides-2.ppt
Py-Slides-2.ppt
TejaValmiki
 
Operator 04 (js)
Operator 04 (js)Operator 04 (js)
Operator 04 (js)
AbhishekMondal42
 
Operator & Expression in c++
Operator & Expression in c++Operator & Expression in c++
Operator & Expression in c++bajiajugal
 

Similar to Operators (20)

Types of Operators in C
Types of Operators in CTypes of Operators in C
Types of Operators in C
 
Opeartor &amp; expression
Opeartor &amp; expressionOpeartor &amp; expression
Opeartor &amp; expression
 
4_A1208223655_21789_2_2018_04. Operators.ppt
4_A1208223655_21789_2_2018_04. Operators.ppt4_A1208223655_21789_2_2018_04. Operators.ppt
4_A1208223655_21789_2_2018_04. Operators.ppt
 
Operators in Python
Operators in PythonOperators in Python
Operators in Python
 
Unit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in cUnit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in c
 
python operators.ppt
python operators.pptpython operators.ppt
python operators.ppt
 
Java basic operators
Java basic operatorsJava basic operators
Java basic operators
 
Java basic operators
Java basic operatorsJava basic operators
Java basic operators
 
Operators used in vb.net
Operators used in vb.netOperators used in vb.net
Operators used in vb.net
 
Operators and it's type
Operators and it's type Operators and it's type
Operators and it's type
 
Report on c
Report on cReport on c
Report on c
 
C++ Expressions Notes
C++ Expressions NotesC++ Expressions Notes
C++ Expressions Notes
 
itft-Operators in java
itft-Operators in javaitft-Operators in java
itft-Operators in java
 
Cprogrammingoperator
CprogrammingoperatorCprogrammingoperator
Cprogrammingoperator
 
Py-Slides-2.ppt
Py-Slides-2.pptPy-Slides-2.ppt
Py-Slides-2.ppt
 
Py-Slides-2 (1).ppt
Py-Slides-2 (1).pptPy-Slides-2 (1).ppt
Py-Slides-2 (1).ppt
 
Py-Slides-2.ppt
Py-Slides-2.pptPy-Slides-2.ppt
Py-Slides-2.ppt
 
Operator 04 (js)
Operator 04 (js)Operator 04 (js)
Operator 04 (js)
 
Operator & Expression in c++
Operator & Expression in c++Operator & Expression in c++
Operator & Expression in c++
 
07 ruby operators
07 ruby operators07 ruby operators
07 ruby operators
 

Recently uploaded

road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
VENKATESHvenky89705
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
gdsczhcet
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
MdTanvirMahtab2
 
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSETECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
DuvanRamosGarzon1
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
AafreenAbuthahir2
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
Pratik Pawar
 
Halogenation process of chemical process industries
Halogenation process of chemical process industriesHalogenation process of chemical process industries
Halogenation process of chemical process industries
MuhammadTufail242431
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
AhmedHussein950959
 
addressing modes in computer architecture
addressing modes  in computer architectureaddressing modes  in computer architecture
addressing modes in computer architecture
ShahidSultan24
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
Intella Parts
 
Democratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek AryaDemocratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek Arya
abh.arya
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
Jayaprasanna4
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
AJAYKUMARPUND1
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
ViniHema
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
Osamah Alsalih
 
LIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.pptLIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.ppt
ssuser9bd3ba
 

Recently uploaded (20)

road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
 
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSETECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 
Halogenation process of chemical process industries
Halogenation process of chemical process industriesHalogenation process of chemical process industries
Halogenation process of chemical process industries
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
 
addressing modes in computer architecture
addressing modes  in computer architectureaddressing modes  in computer architecture
addressing modes in computer architecture
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
 
Democratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek AryaDemocratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek Arya
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
 
LIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.pptLIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.ppt
 

Operators

  • 1. OPERATORS:  A set of operators is available in Verilog. The operator symbols are similar to those in C language  With these operators we can carry out specified operations on the operands and assign the results to a net or a vector set of nets as the case may be. Unary Operators: Unary operators do an operation on a single operand and assign the result to the specified net. All unary operators get precedence over binary and ternary operators. Unary operators and their symbols:
  • 2.  Reduction operators opearate on all bits of a single operand and produce 1 –bit result. The operator list given in previous slide  For reduction and: if any bit is 0 , the result is 0,else if any bit is an X or Z , the result is an X , else the result is 1.  Like that apply for or,nand,nor  for reduction XOR: if any bit is an X or Z the result is X ,else if there are even number of 1’s in the operand, the result is 0,else the result is 1.  a= ‘b0110, b= ‘b0100  then | b is 1  &b is 0  ~^ A is 1  next example myreg = 4’b01x0 ;  then ^myreg is an x
  • 3. Binary operators:  Most operators available are of the binary type. A binary operator takes on two operands; the operator comes in between the two operands in the assignment. x The arithmetic operators treat both the operands as numbers and return the result as a number. x All net and reg operand values are treated as unsigned numbers. x Real and integer operands may be signed quantities.  The result of any arithmetic operation — with the “+” or “–” or with any of the other arithmetic operators discussed later — will have an x value if any of the operand bits has an x or a z value.  Classified into arithmetic operators, logical operators, relational operators, equality operators, bit wise logical operators, operator truth tables, shift operators.
  • 4. Arithmetic operators: The modulus operand is similar to that in C language – It provides the remainder of the division of two numbers. Example: module add_8(a,b,c); input[7:0]a,b; output[7:0]c; assign c = a + b ; // indication of arithmetic binary operator for //addition endmodule
  • 5. Examples: 7/ 4 results 1 // division operation  7 % 4 results 3 // modulus operator  - 7 % 4 results -3 // modulus operator  if any bit of an operand in an arithmetic operation is an x or z , the entire result is x for example ‘b10x0 + ‘b01111 is ‘bxxxxx  the size of the result of an arithmetic expression is determined by the size of the largest operand.
  • 6. Logical operators:  There are two logical operators involving two operands. The operands concerned can be variables or expressions involving variables.  In both cases the result of the operation is a single bit of value 1 (true) or 0 (false).  If a bit in one of the operands is x or z, the result of evaluation of the expression has an x value. Crd = ‘b0 , dgs = ‘b1 then Crd && dgs is 0 Crd||dgs is 1 For vector operands , a non zero vector is treated as a 1, for example abus = ‘b0110 , bbus = ,b0100 Then abus||bbus is 1 also abus&&bbus is also 1
  • 7. Relational operators: There are four relational operators, their details are  A relational operator treats both the operands as binary numbers and compares them.  The result is a 1 (true) bit or a 0 (false) bit. If a bit in either operand is x or z, the result has x (unknown) value.  The operands can be variables or expressions involving variables. Operands of net or reg type are treated as unsigned numbers. Real and integers can be positive or negative (i.e., signed) numbers.
  • 8. Example of relational operators:  23 > 45 is false (value 0),  while 52 < 8’hxff is x  if operands are not of the same size , the smaller operand is zero filled on the MSB side , for example ‘b1000 >= ‘b01110 is equivalent to ‘b01000>= ‘b01110 which is false value 0 is the output
  • 9. Equality operators:  The equality operator makes a bit-by-bit comparison of the two operands and produces a result bit.  The result bit is a 1 (true) if the operand condition is satisfied; otherwise it is 0 (false).  The operands can be variables or expressions involving variables.  If the operands are of unequal length, the shorter one is zero filled to match the larger operand.  The operators in this category are only of two types – those to test the equality and those to test inequality.  == (logical equality)  != (logical inequality)  ===(case equality)  !== (case inequality) The result is 0 if the comparison is false, else the result is a 1, in case comparisons , values x and z are compared strictly as values that is with no interpretations.
  • 10. Equality operators and their symbols:
  • 11.  Examples of Equality operators: Example data = ‘b11x0 ,addr = ‘b11x0 then data = =addr is unknown , that is the value x and  if data ===addr is true , that is the value 1.  If the operands are of unequal lengths , the smaller operand is zero filled on the MSB side, that is on the left, for example 2’b10 == 4’b0010 is same as 4’b0010==4’b0010 which is true the result value is 1
  • 12. Bit wise logical operators:  The operator does a specified bit-by-bit operation on the two operands and produces a set of result bits.  The result is (bit-wise) as wide as the wider operand.If the width of one of the operands is less than that of the other, it is bit-extended. by filling zero bits and the widths are matched.  Subsequently, the specified operation is carried out. If one of the operands has an x or z bit in it, the corresponding result bit is x. Either operand can be a single variable or an expression involving variables.
  • 13. Operator Truth Table: bit wise operators  The truth tables for different types of bit-wise operators are given in Table Note that an z input is treated as an x value.
  • 14. Examples of bitwise operators: A= ‘b0110 ,B =‘b0100 then A | B is 0110 , A& B is 0100 If the operands are unequal in length, the smaller operand is zero filled on the most significant side for example ‘b0110 ^ ‘b10000 Is same as ‘b00110 ^ ‘b10000 Answer is ‘b10110
  • 15. Shift Operators:  The << operator executes left shift operation, while the >> operator executes the right shift operation. In either case the operand specified on the left is shifted by the number of bits specified on the right. The shifting is done irrespective of whether the bits are 0, 1, x, or z. The bits shifted out are lost.  The vacated positions created as a result of the shifting are filled with zeroes.  If the right operand is x or z, the result has an x value. If the right operand is negative, the left operand remains unchanged.
  • 16. Shift Operators contd..:  the shift operation shifts left operand by the right operand number of times. It is a logical shift .The vacated bits are filled with 0 , if the right operand evaluates to an x or z, the result of the shift operation is an x.  reg[0:7] Qreg; Qreg= 4’b0111; qreg >> 2 is 8’b0000_0001
  • 17. Ternary Operator: Verilog has only one ternary operator – the conditional operator.  It checks a condition and does a branching. It is a versatile and powerful operator. The general form is A?b:c  The conditional operation is made up of two operators – “?” and “:” – and three operands.  The two operands separate the three operators in the order shown.  The operational sequence of the operation is as follows: “A” is evaluated first. If A is true, b is evaluated. If A is false, c is evaluated. If A evaluates to an ambiguous result, both b and c are evaluated.
  • 18. Conditional operator contd… cond_expr ? expr1:expr2  If cond_expr is true (that is ,has a value 1), expr 1 is selected, if cond_expr is false (value 0) , expr2 is selected.  if cond_expr is an x or a z , the result is a bitwise operation on expr1 and expr2 with the following logic: 0 with 0 gives 0, 1 with gives 1, rest are x.  here is an example  wire [0:2] student = marks >18 ? Grade_A : grade_c;  the expression marks > 18 is computed ; if true , Grade_A is assighned to student , if marks <=18 , grade_C is assighed to student Another example always #5 ctr = (ctr!=25) ? (ctr+1) : 5;  The expression in the procedural assignment says that if ctr is not equal to 25 increment ctr, else if ctr becomes 25, reset to 5.
  • 19. Operator priority:  A clear understanding of the operator precedence makes room for a compact design description. But it may lead to ambiguity and to inadvertent errors.  Whenever one is not sure of the operator priorities, it is better to resort to the use of parentheses and ensure clarity and accuracy of expressions.  Further, some synthesizers may not interpret the operator precedence properly. These too call for the apt use of parentheses.  In any expression, operators associate from left to right. Ternary operator is the only exception to this; it associates from right to left.
  • 20. Examples:  P = Q – R + S; Here R is subtracted from Q and then S is added to the result. However, operator precedence does not cause any ambiguity or change the result here.  P = Q – R / S; In the above case the “divide” operator “/” has precedence over the “subtract” operator “–”. Hence R will be divided by S, and the result will be subtracted from Q.  If division of (Q – R) is desired, the expression has to be recast as P = (Q – R) / S;  In a lengthier expression such as P = a1 – a2 / a3 + a4 * a5; The operation is equivalent to P = a1 – ( a2 / a3 ) + ( a4 * a5 ); Use of parentheses adds to clarity especially in operations involving more than two operators.  The operation P > Q – R is the same as P > (Q – R)  since the relational operator “>” has a lower precedence than the algebraic operator “–”.  Similarly, the expression P + Q <= R is the same as ( P + Q ) <= R.