SlideShare a Scribd company logo
1
Verilog HDLVerilog HDL
Lecture 7
2
Logical Operators
• && → logical AND
• | | → logical OR
• ! → logical NOT
• Operands evaluated to ONE bit value: 0, 1 or x
• Result is ONE bit value: 0, 1 or x
• A= 6; A&&B → 1&&0 → 0
• B = 0; A | | !B → 1| |1 → 1
• C= x; C | | B → x | | 0 → x, C&&B = 0
Lecture 7
3
Bitwise Operators
• & → bitwise AND
• | → bitwise OR
• ~ → bitwise NOT
• ^ → bitwise XOR
• ~^ or ^~ → bitwise XNOR
• Operation on bit by bit basis
Lecture 7
4
Bitwise Operators
•
Lecture 7
5
Reduction Operators
• & → AND
• | → OR
• ~& → NAND
• ~| → NOR
• ^ → XOR
• ~^ or ^~ → XNOR
• One multi-bit operand → One single-bit result
• a = 4’b1001;
• c = |a ; // c = 1|0|0|1 = 1
Lecture 7
6
Shift Operators
• >> → shift right
• << → shift left
• Result is same size as first operand, always zero filled
• a = 4’b1010;
• d = a>>2; //d= 0010
• c = a<<1; //c= 0100
Lecture 7
7
Concatenation Operator
• {op1, op2, ..} → concatenates op1, op2, .. to single
number
• Operands must be sized !!
reg a;
reg [2:0] b, c;
..
a = 1’b 1;
b = 3’b 010;
c = 3’b 101;
catx = {a, b, c}; //catx = 1_010_101
Lecture 7
8
Concatenation Operator
caty = {b, 2’b11, a};//caty = 010_11_1
catz = {b, 1}; // WRONG !!
• Replication ..
catr = {4{a}, b, 2{c}};
// catr = 1111_010_101101
Lecture 7
9
Example of Replication
We want to multiply A and B 5-bits numbers.
Lecture 7
10
Replication: Verilog Code of Multiplier
module mul_5x5(A, B, mul_out); // Multiplier Unsigned X
Unsigned Number
input [4:0] A, B ;
output [9:0] mul_out ;
wire [4:0] pp0, pp1, pp2, pp3, pp4 ;
wire [9:0] mul_out ;
assign ppo = A & {5{B[0]}} ;
assign pp1 = A & {5{B[1]}} ;
assign pp2 = A & {5{B[2]}} ;
assign pp3 = A & {5{B[3]}} ;
assign pp4 = A & {5{B[4]}} ;
assign mul_out = pp0 + {pp1, 1’b0} + {pp2, 2’b0} + {pp3,
3’b0} +{pp4, 4’b0} ;
endmodule
Lecture 7
11
Relational Operators
• > → greater than
• < → less than
• >= → greater or equal than
• <= → less or equal than
• Result is one bit value: 0, 1 or x
1 > 0 → 1
’b1x1 <= 0 → x
10 < z → x
Lecture 7
12
Equality Operators
• == → logical equality
• != → logical inequality
• === → case equality
• !== → case inequality
• 4’b 1z0x == 4’b 1z0x → x
• 4’b 1z0x != 4’b 1z0x → x
• 4’b 1z0x === 4’b 1z0x → 1
• 4’b 1z0x !== 4’b 1z0x → 0
Lecture 7
13
Conditional Operator
• cond_expr ? true_expr : false_expr
• Like a 2-to-1 mux ..
Lecture 7
14
Arithmetic Operators
• +, -, *, /, %
• If any operand is x the result is x
• Negative registers:
• regs can be assigned negative but are
treated as unsigned
reg [15:0] regA;
Lecture 7
15
Arithmetic Operators
regA = -16’d12;
//stored as 216
-12 = 65524
regA/3 evaluates to 21841
•Negative integers:
• can be assigned negative values
• different treatment depending on base
specification or not
Lecture 7
16
Arithmetic Operators
reg [15:0] regA;
integer intA;
..
intA = -12/3;
//evaluates to –4 (no base
spec)
intA = -’d12/3;
//evaluates to 1431655761
(base spec) Lecture 7
17
Operator Precedence
Lecture 7

More Related Content

PPTX
Encoders and decoders
PPTX
Multiplexers
PPTX
multiplexer 4 input
PPTX
Array multiplier
PPT
Design and development of carry select adder
PPTX
Verilog operators.pptx
PPTX
Half adder and full adder
PDF
2 bit comparator, 4 1 Multiplexer, 1 4 Demultiplexer, Flip Flops and Register...
Encoders and decoders
Multiplexers
multiplexer 4 input
Array multiplier
Design and development of carry select adder
Verilog operators.pptx
Half adder and full adder
2 bit comparator, 4 1 Multiplexer, 1 4 Demultiplexer, Flip Flops and Register...

What's hot (20)

PDF
1Sem-MTech-Design For Verification Notes-Unit2-Verification Tools
PPTX
Rules of Karnaugh Map
PDF
Verilog Tasks & Functions
PDF
JK flip flops
PDF
Dual port ram
PDF
Magnitude comparator
PPT
carry look ahead adder
PPTX
Decoders-Digital Electronics
PDF
List of vlsi companies in bangalore
PPTX
Travelling salesman problem
PPTX
SHIFT REGISTERS
PPTX
Encoder and decoder
PPTX
Radix 4 booth
PPTX
MICROPROCESSOR AND INTERFACING
PPTX
Decoder Full Presentation
PDF
Binary multipliers
PPTX
Asynchronous Sequential Circuit-Unit 4 ppt
PPT
8085-microprocessor
PPTX
Combinational Circuits & Sequential Circuits
PPTX
Logic families
1Sem-MTech-Design For Verification Notes-Unit2-Verification Tools
Rules of Karnaugh Map
Verilog Tasks & Functions
JK flip flops
Dual port ram
Magnitude comparator
carry look ahead adder
Decoders-Digital Electronics
List of vlsi companies in bangalore
Travelling salesman problem
SHIFT REGISTERS
Encoder and decoder
Radix 4 booth
MICROPROCESSOR AND INTERFACING
Decoder Full Presentation
Binary multipliers
Asynchronous Sequential Circuit-Unit 4 ppt
8085-microprocessor
Combinational Circuits & Sequential Circuits
Logic families
Ad

Viewers also liked (16)

PPT
Sec3 chapter5 bonding singapore_slideshare
PPT
Bmc social studies_chapter3_healthcare(spore&uk systems)
PPTX
Florante at laura
PPTX
Sec3 english language_comprehension(thesummaryqn)
ODP
Poap de 2º eso a 3º eso 2016 2017
PPTX
Bmc cold war lect 3
PPTX
Singular and plural nouns for first graders
PPT
Bmc social studies_chapter2b_governance in singapore(poppolicies)
PPTX
Bmc cold war lect 4_cuban_missilecrisis
PPTX
Onset and rime For First Graders
PPT
Rules in forming the plural of noun (grade 1-2)
PPT
Sec3 chapter6 diplomacy & deterrence(singapore)_slideshare
PPT
Making inferences
PPT
Kinds of nouns according to number (grade 1)
PPTX
Elements of the Story: Problem and solution
PPTX
Bmc o&n english_language_composition(situational writing)(formal letter)_slid...
Sec3 chapter5 bonding singapore_slideshare
Bmc social studies_chapter3_healthcare(spore&uk systems)
Florante at laura
Sec3 english language_comprehension(thesummaryqn)
Poap de 2º eso a 3º eso 2016 2017
Bmc cold war lect 3
Singular and plural nouns for first graders
Bmc social studies_chapter2b_governance in singapore(poppolicies)
Bmc cold war lect 4_cuban_missilecrisis
Onset and rime For First Graders
Rules in forming the plural of noun (grade 1-2)
Sec3 chapter6 diplomacy & deterrence(singapore)_slideshare
Making inferences
Kinds of nouns according to number (grade 1)
Elements of the Story: Problem and solution
Bmc o&n english_language_composition(situational writing)(formal letter)_slid...
Ad

Similar to Verilog lect 7 (20)

PPT
Assic 7th Lecture
DOCX
GSP 215 Entire Course NEW
PPTX
C++ Programming Basics.pptx
PPT
FP 201 Unit 2 - Part 3
PPT
3306617
ODP
Ruby Basics by Rafiq
PPT
verilog_1.ppt
PPTX
Operators and expressions in C++
PDF
Operators in python
PPTX
Reducing computational complexity of Mathematical functions using FPGA
PPTX
Operators in c++ programming types of variables
DOC
Gsp 215 Exceptional Education / snaptutorial.com
PDF
Operators_in_Python_Simplified_languages
PPTX
vlsi design using verilog presentaion 1
PDF
The Ring programming language version 1.5.4 book - Part 77 of 185
PPTX
Python PCEP Logic Bit Operations
PPTX
Matlab operators
DOCX
Labsheet2 stud
PPTX
Operators expressions-and-statements
Assic 7th Lecture
GSP 215 Entire Course NEW
C++ Programming Basics.pptx
FP 201 Unit 2 - Part 3
3306617
Ruby Basics by Rafiq
verilog_1.ppt
Operators and expressions in C++
Operators in python
Reducing computational complexity of Mathematical functions using FPGA
Operators in c++ programming types of variables
Gsp 215 Exceptional Education / snaptutorial.com
Operators_in_Python_Simplified_languages
vlsi design using verilog presentaion 1
The Ring programming language version 1.5.4 book - Part 77 of 185
Python PCEP Logic Bit Operations
Matlab operators
Labsheet2 stud
Operators expressions-and-statements

Recently uploaded (20)

PPT
Teaching material agriculture food technology
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Approach and Philosophy of On baking technology
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
A Presentation on Artificial Intelligence
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
NewMind AI Monthly Chronicles - July 2025
PPTX
Big Data Technologies - Introduction.pptx
PDF
cuic standard and advanced reporting.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Machine learning based COVID-19 study performance prediction
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Review of recent advances in non-invasive hemoglobin estimation
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Chapter 3 Spatial Domain Image Processing.pdf
Teaching material agriculture food technology
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Unlocking AI with Model Context Protocol (MCP)
Approach and Philosophy of On baking technology
Reach Out and Touch Someone: Haptics and Empathic Computing
CIFDAQ's Market Insight: SEC Turns Pro Crypto
“AI and Expert System Decision Support & Business Intelligence Systems”
Spectral efficient network and resource selection model in 5G networks
A Presentation on Artificial Intelligence
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
NewMind AI Monthly Chronicles - July 2025
Big Data Technologies - Introduction.pptx
cuic standard and advanced reporting.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Machine learning based COVID-19 study performance prediction
Understanding_Digital_Forensics_Presentation.pptx
NewMind AI Weekly Chronicles - August'25 Week I
Review of recent advances in non-invasive hemoglobin estimation
The AUB Centre for AI in Media Proposal.docx
Chapter 3 Spatial Domain Image Processing.pdf

Verilog lect 7

  • 2. 2 Logical Operators • && → logical AND • | | → logical OR • ! → logical NOT • Operands evaluated to ONE bit value: 0, 1 or x • Result is ONE bit value: 0, 1 or x • A= 6; A&&B → 1&&0 → 0 • B = 0; A | | !B → 1| |1 → 1 • C= x; C | | B → x | | 0 → x, C&&B = 0 Lecture 7
  • 3. 3 Bitwise Operators • & → bitwise AND • | → bitwise OR • ~ → bitwise NOT • ^ → bitwise XOR • ~^ or ^~ → bitwise XNOR • Operation on bit by bit basis Lecture 7
  • 5. 5 Reduction Operators • & → AND • | → OR • ~& → NAND • ~| → NOR • ^ → XOR • ~^ or ^~ → XNOR • One multi-bit operand → One single-bit result • a = 4’b1001; • c = |a ; // c = 1|0|0|1 = 1 Lecture 7
  • 6. 6 Shift Operators • >> → shift right • << → shift left • Result is same size as first operand, always zero filled • a = 4’b1010; • d = a>>2; //d= 0010 • c = a<<1; //c= 0100 Lecture 7
  • 7. 7 Concatenation Operator • {op1, op2, ..} → concatenates op1, op2, .. to single number • Operands must be sized !! reg a; reg [2:0] b, c; .. a = 1’b 1; b = 3’b 010; c = 3’b 101; catx = {a, b, c}; //catx = 1_010_101 Lecture 7
  • 8. 8 Concatenation Operator caty = {b, 2’b11, a};//caty = 010_11_1 catz = {b, 1}; // WRONG !! • Replication .. catr = {4{a}, b, 2{c}}; // catr = 1111_010_101101 Lecture 7
  • 9. 9 Example of Replication We want to multiply A and B 5-bits numbers. Lecture 7
  • 10. 10 Replication: Verilog Code of Multiplier module mul_5x5(A, B, mul_out); // Multiplier Unsigned X Unsigned Number input [4:0] A, B ; output [9:0] mul_out ; wire [4:0] pp0, pp1, pp2, pp3, pp4 ; wire [9:0] mul_out ; assign ppo = A & {5{B[0]}} ; assign pp1 = A & {5{B[1]}} ; assign pp2 = A & {5{B[2]}} ; assign pp3 = A & {5{B[3]}} ; assign pp4 = A & {5{B[4]}} ; assign mul_out = pp0 + {pp1, 1’b0} + {pp2, 2’b0} + {pp3, 3’b0} +{pp4, 4’b0} ; endmodule Lecture 7
  • 11. 11 Relational Operators • > → greater than • < → less than • >= → greater or equal than • <= → less or equal than • Result is one bit value: 0, 1 or x 1 > 0 → 1 ’b1x1 <= 0 → x 10 < z → x Lecture 7
  • 12. 12 Equality Operators • == → logical equality • != → logical inequality • === → case equality • !== → case inequality • 4’b 1z0x == 4’b 1z0x → x • 4’b 1z0x != 4’b 1z0x → x • 4’b 1z0x === 4’b 1z0x → 1 • 4’b 1z0x !== 4’b 1z0x → 0 Lecture 7
  • 13. 13 Conditional Operator • cond_expr ? true_expr : false_expr • Like a 2-to-1 mux .. Lecture 7
  • 14. 14 Arithmetic Operators • +, -, *, /, % • If any operand is x the result is x • Negative registers: • regs can be assigned negative but are treated as unsigned reg [15:0] regA; Lecture 7
  • 15. 15 Arithmetic Operators regA = -16’d12; //stored as 216 -12 = 65524 regA/3 evaluates to 21841 •Negative integers: • can be assigned negative values • different treatment depending on base specification or not Lecture 7
  • 16. 16 Arithmetic Operators reg [15:0] regA; integer intA; .. intA = -12/3; //evaluates to –4 (no base spec) intA = -’d12/3; //evaluates to 1431655761 (base spec) Lecture 7