SlideShare ist ein Scribd-Unternehmen logo
1 von 34
Digital Design Using Verilog
- For Absolute Beginners
LECTURE6 : VERILOG OPERATORS
Introduction
• Normally the operators work on any specific data
types or operands to give expected results.
• As Verilog is mainly used to describe the hardware
behavior and functioning, it supports a variety of
pre-defined operators .
• But it should be always remembered that not all the
operands are synthesizable.
•Some of these operators are similar to the operators
used in the C programming language.
•Each operator type is denoted by a symbol
contd
• The different types of Operators supported are
• Assignment operator
• Arithmetic operators
• Logical operators
• relational, equality operators
• Bitwise operators
• Reduction operators
• Shift operators
• Concatenation and Conditional etc.
ASSIGNMENT OPERATOR
• Verilog uses the equal sign (=) to denote an
assignment.
• The left-hand side (LHS) of the assignment is the
target signal. The right-hand side (RHS) contains the
input arguments and can contain both signals,
constants, and operators.
• Ex: Y = a & b;
• F2 = 8’hAA;
• F1 = A ;
23 June 2020 4yayavaram@yahoo.com
• The most fundamental operators are Arithmetic
operators.
• Broadly there are two types of arithmetic operators.
(i).Unary and (ii).Binary
Unary Operators: A unary operator is an operator that
takes a single operand in an expression or a statement.
+ : addition % : modulus
- : subtraction ** : exponentiaion
* : multiplication / : divide
23 June 2020 5yayavaram@yahoo.com
ARITHMETIC OPERATORS
contd
Ex: +A ; - Y ; - (A+B) ; ** D Exponential D etc.
• Binary Operators : A binary operator is an operator
that operates on two operands and manipulates them
to return a result.
• Y = (A+B) * (B+C)
• X = (A+B) / (C-D)
• D =A + D : Addition operator surrounded by two
operands
23 June 2020 6yayavaram@yahoo.com
Illustration
• module Arithmetic (A, B, Y1, Y2, Y3, Y4, Y5);
input [2:0] A, B;
output [3:0] Y1;
output [4:0] Y3;
output [2:0] Y2, Y4, Y5;
reg [3:0] Y1;
reg [4:0] Y3;
reg [2:0] Y2, Y4, Y5;
always @(A or B)
begin
Y1=A+B; //addition operation
Y2=A-B; //subtraction operation
Y3=A*B; //multiplication operation
Y4=A/B; //division operation
Y5=A%B; //modulus of A divided by B
end
endmodule
23 June 2020
7
yayavaram@yahoo.com
% Modulus operator
• The modulus operator is denoted by the symbol %.
• For example A % B, gives the remainder when the first operand is
divided by the second, and thus is zero when B divides A exactly.
• The result of a modulus operation shall take the sign of the first
operand.
23 June 2020 8yayavaram@yahoo.com
Logical Operator
• These operators deals with true or false logic . i.e
the logical operators return either 0 or 1.
• Logical comparison operators are used in conjuction
with relational and equality operators .
• These operators are widely used in if ; While
statements. And, provide a means to perform
multiple comparisons within a single expression.
• ! : Logical negation. Ex : ! (A && B)
&& : Logical AND
|| : Logical OR Ex : A || B
23 June 2020 9yayavaram@yahoo.com
contd
• Logical operators produce 1-bit results.
• The result of && is one if none of the operands is 0.
• The result of || is 1 if at least one of the operands is
non-zero.
• The ! Operator complements its operand and
produces 1 or a 0. If X or Z appears in an operand
of the logical operand ,an X will be the result.The !
Operator has the highest precedence, followed by
&& and || .
23 June 2020 10yayavaram@yahoo.com
Examples
• Let A = 3’b101 ; B = 3’b000; C = 3’B01X
• !A = 1b0 ;
• !B = 1’b1 ;
• !C = 1’Bx
• A && B => 1’b 0 ; // since one operand is zero
• B&&C=> 1’bX;// one operand is unknown
• A || B => 1’b1 // one of the operands is non-zero
• B || C => 1’bX
23 June 2020 11yayavaram@yahoo.com
Example-2
• module ex_logical (A, B, C, D, E, F, Y);
input [2:0] A, B, C, D, E, F;
output Y;
reg Y;
always @ (A or B or C or D or E or F)
begin
if ((A= =B) && ((C>D) || !(E<F)))
Y=1;
else
Y=0;
end
endmodule
23 June 2020 12yayavaram@yahoo.com
Relational & Equality Operators
• These operators are mainly used to compare data
values.
• = = Equality ; != Not equal(Inequality)
• = = = : Case equality ; ! = = Case inequality.
• >= Greater or equal ; <= Less than or equal
• > Greater ; < Less
• Here = = ; ! = ; = = = are the equality operators
• Case equality is used to compare the values with x
or z.
23 June 2020 13yayavaram@yahoo.com
Example for Case Equality
• Let A = 1011; B = 1011
A = =B ; The result is true;
• Let A = 0110 ; B = 1011;
A == B ; The result is false ,as they are not equal.
• Suppose A= 101X ; B = 101X ;
• A ==B ; The result is unknown x
So, One has to use case Equality operator. In a case equality
A = = = B ; The result is 1 (true).
• Suppose A=101X & B= 011X.The the result will be False
i.e 0.
23 June 2020 14yayavaram@yahoo.com
Illustration
• module ex_relational (A, B, Y1, Y2, Y3, Y4);
input [2:0] A, B;
output Y1, Y2, Y3, Y4;
reg Y1, Y2, Y3, Y4;
always @(A or B)
begin
Y1=A<B;//less than
Y2=A<=B;//less than or equal to
Y3=A>B;//greater than
if (A>B)
Y4=1;
else
Y4=0;
end
endmodule
23 June 2020 15yayavaram@yahoo.com
Illustration-Equality operators
• module ex_equality (a, b, y1, y2, y3);
input [2:0] a,b;
output y1,y2;
output [2:0] y3;
reg y1,y2;
reg [2:0] y3;
always @(a or b)
begin
y1= a= =b;// y1=1 if a equivalent to b
y2=a!=b;//y2=1 if a not equivalent to b
if (a= =b) //
y3= a;
else
y3= b;
end
endmodule
23 June 2020 16yayavaram@yahoo.com
Bitwise Operators
• Verilog bitwise operators can be either unary or
binary. Result is always the size of largest operand.
• i.e the meaning is , logical bit-wise operators take
two single or multiple operands on either side of the
operator and return a single bit result.
• The only exception is the NOT operator, which
negates the single operand that follows.
• Verilog does not have the equivalent of NAND or
NOR operator, their function is implemented by
negating the AND and OR operators.
23 June 2020 17yayavaram@yahoo.com
contd
• ~ : bitwise NOT(Invert)
• & : bit wise AND
• | : bitwise OR
• ^ : bitwise Exclusive OR
• ~ ^ : bitwise exclusive NOR
• Bit wise operators operate on each bit and returns a
value that is also a bit.
23 June 2020 18yayavaram@yahoo.com
Bitwise Operators contd
• If two operands are unequal ,the smaller one is left
extended by adding zeros.
• Ex : a = 4’b1001 and b = 3’b 101.
To find a & b , the second operand is taken as
b = 4’b0101 and then logical & operation is
performed.
a & b => 4’b0001
The size of the result is 4 bits .
23 June 2020 19yayavaram@yahoo.com
Examples
• assign a => 4’b1011 ; b=> 4’b1101 ; c => 4’b0111;
• ~ a => 4’b 0100 ; ~b=> 4’b0010 ; ~c => 4’b1000;
• a & b => 4’b1001 ; b & c => 4’b 0101
• a | b => 4’b1111 ; b | c => 4’b1111
• a ^ b => 4’b 0110 ; b ^ c => 4’b 1010
• a ^ ~b => 4’b 1001 ; b ^ ~ c => 4’b 0101
23 June 2020 20yayavaram@yahoo.com
Example-2
• module ex_Bitwise (A, B, Y);
input [6:0] A;
input [5:0] B;
output [6:0] Y;
reg [6:0] Y;
always @(A or B)
begin
Y(0)=A(0)&B(0); // binary AND
Y(1)=A(1)|B(1); // binary OR
Y(2)=!(A(2)&B(2)); // negated AND (NAND)
Y(3)=!(A(3)|B(3)); // negated OR (NOR)
Y(4)=A(4)^B(4); // binary XOR
Y(5)=A(5)~^B(5); // binary XNOR
Y(6)=!A(6); // unary negation
end
endmodule
23 June 2020 21yayavaram@yahoo.com
Reduction Operators
• Reduces a vector to a single bit value. i.e a multibit
value is reduced to a single bit value.
• Majority of the times this is a unary operator.
• To say in terms of hardware , This reduction
operator works like a multiple input bits logic
gate,which accepts a single word operand and
produces a single bit as output.
• The operators are
• & and ; ~ & not and(nand) ; | or ; ~ | not or (nor)
• ^ x-or ; ~ ^ not or (x-nor)
23 June 2020 22yayavaram@yahoo.com
Examples
• For ex, in the ‘and’ gate for
the Inputs 1011 the output is 0.
• Similarly let us consider or gate as shown below.
• So, these reduction operands are reducing a multibit
operands into single bit operands.
• s.23 June 2020 23yayavaram@yahoo.com
Examples contd
• Let us consider the x-or gate .
• y = ^ A where A = 4’b0110
i.e y = 0 ^1^1^0 = 1
23 June 2020 24yayavaram@yahoo.com
Example for Reduction Operator
• module red_ex(a,b,c,y1,y2,y3);
input a, b, c ;
output y1,y2,y3 ;
wire[7:0] a,b,c ;
wire [7:0]y1,y2,y3 ;
assign a=4’b0111;
assign b=4’b0111;
assign c=4’b0100;
assign y1 = ^a // gives y1 = 1
assign y2 = &(a^b); //gives y2=0
assign y3 = ^a&^b; //gives y3 = 1
23 June 2020 25yayavaram@yahoo.com
SHIFT OPERATORS
• Generally ,the shift operators are used to shift the
operand bits either left or right.
• Shift operators require two operands. The operand
before the operator contains data to be shifted and
the operand after the operator contains the
number of single bit shift operations to be
performed.
• Verilog has two types of shift operators .
• i. Logical Shift and ii.Arithmetic shift operators.
23 June 2020 26yayavaram@yahoo.com
• This shifting is done in two ways. Either Left shift
or Right shift.
• Logical Right shift operator is denoted by >>
• Logical Left shift operator is <<.
• In logical shift vacated positions are always filled
with zero(0).
• In terms of the operation right shift means divide by
2 also.
• Similarly Left shift operation will result in multiply
of the operand by 2.
23 June 2020 27yayavaram@yahoo.com
contd
Arithmetic Shift Operators
• Right arithmetic shift is denoted by the symbol >>>
• Left arithmetic shift is denoted by <<<.
• In arithmetic shift: For signed numbers , the vacated
position is filled with sign bit value(MSB bit)
• For unsigned ,the vacated positions are filled with
zero.
23 June 2020 28yayavaram@yahoo.com
Code-Example
• module ex_shift (a, y1, y2);
input [7:0] a;
output [7:0] y1, y2;
parameter b=3; reg [7:0] y1, y2;
always @(a)
begin
y1=a<<b; //logical shift left
y2=a>>b; //logical shift right
end
• endmodule
23 June 2020 29yayavaram@yahoo.com
Concatenation Operator{,}
• The concatenation operator "{ , }" combines or
(concatenates) the bits of two or more data objects.
• The objects may be scalar (single bit) or vectored (muliple
bit).
• Mutiple concatenations may be performed with a constant
prefix and is known as replication.
• For ex: By concatenating two 4-bit operands, an 8-bit
operand is formed.
• Remember it is not direct arithmetic addition.
• Ex: Let A= 4’b1011; B=4’b 1010;
assign y = {a,b} gives y=> 8b’10111010
23 June 2020 30yayavaram@yahoo.com
Replicate Operator
• It replicates the operand for a specified number of
times.( or copied specified number of times).
• For ex: assign y = {3{3’b110}} results in
• y = 9’b110110110
23 June 2020 31yayavaram@yahoo.com
Conditional Operator(?)
• An expression using conditional operator evaluates
the logical expression before the "?".
• If the expression is true then the expression before
the colon (:) is evaluated and assigned to the output.
• If the logical expression is false then the expression
after the colon is evaluated and assigned to the
output.
23 June 2020 32yayavaram@yahoo.com
Example code
• To understand the Conditional operator lets consider
the 2:1 Mux example.
Ex: module mymux2_1(A,B,S,Y);
output Y;
input A,B,S;
assign Y= S ? B:A;
endmodule
Note: In the above ,first the ‘S’ is tested .If it is
true,then Y= B else Y = A
23 June 2020 33yayavaram@yahoo.com
The Conclusion
23 June 2020 34yayavaram@yahoo.com

Weitere ähnliche Inhalte

Was ist angesagt?

Verilog VHDL code Decoder and Encoder
Verilog VHDL code Decoder and EncoderVerilog VHDL code Decoder and Encoder
Verilog VHDL code Decoder and EncoderBharti Airtel Ltd.
 
Verilog Tutorial - Verilog HDL Tutorial with Examples
Verilog Tutorial - Verilog HDL Tutorial with ExamplesVerilog Tutorial - Verilog HDL Tutorial with Examples
Verilog Tutorial - Verilog HDL Tutorial with ExamplesE2MATRIX
 
UNIT-I DIGITAL SYSTEM DESIGN
UNIT-I DIGITAL SYSTEM DESIGN UNIT-I DIGITAL SYSTEM DESIGN
UNIT-I DIGITAL SYSTEM DESIGN Dr.YNM
 
Concepts of Behavioral modelling in Verilog HDL
Concepts of Behavioral modelling in Verilog HDLConcepts of Behavioral modelling in Verilog HDL
Concepts of Behavioral modelling in Verilog HDLanand hd
 
Gate level design -For beginners
Gate level design -For beginnersGate level design -For beginners
Gate level design -For beginnersDr.YNM
 
Fsm sequence detector
Fsm sequence detector Fsm sequence detector
Fsm sequence detector lpvasam
 
Basic concepts in Verilog HDL
Basic concepts in Verilog HDLBasic concepts in Verilog HDL
Basic concepts in Verilog HDLanand hd
 
Delays in verilog
Delays in verilogDelays in verilog
Delays in verilogJITU MISTRY
 
APB protocol v1.0
APB protocol v1.0APB protocol v1.0
APB protocol v1.0Azad Mishra
 
DIgital clock using verilog
DIgital clock using verilog DIgital clock using verilog
DIgital clock using verilog Abhishek Sainkar
 
Magnitude comparator
Magnitude comparatorMagnitude comparator
Magnitude comparatorPreet_patel
 
Bcd to 7 segment display
Bcd to 7 segment displayBcd to 7 segment display
Bcd to 7 segment displayMaulik Sanchela
 
Verilog Test Bench
Verilog Test BenchVerilog Test Bench
Verilog Test BenchDr.YNM
 

Was ist angesagt? (20)

Switch level modeling
Switch level modelingSwitch level modeling
Switch level modeling
 
Verilog VHDL code Decoder and Encoder
Verilog VHDL code Decoder and EncoderVerilog VHDL code Decoder and Encoder
Verilog VHDL code Decoder and Encoder
 
Verilog Tutorial - Verilog HDL Tutorial with Examples
Verilog Tutorial - Verilog HDL Tutorial with ExamplesVerilog Tutorial - Verilog HDL Tutorial with Examples
Verilog Tutorial - Verilog HDL Tutorial with Examples
 
Verilog
VerilogVerilog
Verilog
 
UNIT-I DIGITAL SYSTEM DESIGN
UNIT-I DIGITAL SYSTEM DESIGN UNIT-I DIGITAL SYSTEM DESIGN
UNIT-I DIGITAL SYSTEM DESIGN
 
Concepts of Behavioral modelling in Verilog HDL
Concepts of Behavioral modelling in Verilog HDLConcepts of Behavioral modelling in Verilog HDL
Concepts of Behavioral modelling in Verilog HDL
 
Gate level design -For beginners
Gate level design -For beginnersGate level design -For beginners
Gate level design -For beginners
 
Verilog lab manual (ECAD and VLSI Lab)
Verilog lab manual (ECAD and VLSI Lab)Verilog lab manual (ECAD and VLSI Lab)
Verilog lab manual (ECAD and VLSI Lab)
 
Fsm sequence detector
Fsm sequence detector Fsm sequence detector
Fsm sequence detector
 
Basic concepts in Verilog HDL
Basic concepts in Verilog HDLBasic concepts in Verilog HDL
Basic concepts in Verilog HDL
 
Verilog tutorial
Verilog tutorialVerilog tutorial
Verilog tutorial
 
Delays in verilog
Delays in verilogDelays in verilog
Delays in verilog
 
APB protocol v1.0
APB protocol v1.0APB protocol v1.0
APB protocol v1.0
 
Data Flow Modeling
Data Flow ModelingData Flow Modeling
Data Flow Modeling
 
DIgital clock using verilog
DIgital clock using verilog DIgital clock using verilog
DIgital clock using verilog
 
Magnitude comparator
Magnitude comparatorMagnitude comparator
Magnitude comparator
 
Bcd to 7 segment display
Bcd to 7 segment displayBcd to 7 segment display
Bcd to 7 segment display
 
Verilog Test Bench
Verilog Test BenchVerilog Test Bench
Verilog Test Bench
 
VHDL - Part 2
VHDL - Part 2VHDL - Part 2
VHDL - Part 2
 
8 Bit ALU
8 Bit ALU8 Bit ALU
8 Bit ALU
 

Ähnlich wie Verilog operators

Matlab operators
Matlab operatorsMatlab operators
Matlab operatorsAswin Pv
 
C operators
C operators C operators
C operators AbiramiT9
 
3.OPERATORS_MB.ppt .
3.OPERATORS_MB.ppt                      .3.OPERATORS_MB.ppt                      .
3.OPERATORS_MB.ppt .happycocoman
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++Neeru Mittal
 
Csci101 lect09 vectorized_code
Csci101 lect09 vectorized_codeCsci101 lect09 vectorized_code
Csci101 lect09 vectorized_codeElsayed Hemayed
 
Python PCEP Logic Bit Operations
Python PCEP Logic Bit OperationsPython PCEP Logic Bit Operations
Python PCEP Logic Bit OperationsIHTMINSTITUTE
 
C++ Programming Basics.pptx
C++ Programming Basics.pptxC++ Programming Basics.pptx
C++ Programming Basics.pptxZntalemAbebe
 
8. operators
8. operators8. operators
8. operatorsWay2itech
 
4. operators in c programming by digital wave
4. operators in  c programming by digital wave4. operators in  c programming by digital wave
4. operators in c programming by digital waveRahulSharma4566
 
03. Operators Expressions and statements
03. Operators Expressions and statements03. Operators Expressions and statements
03. Operators Expressions and statementsIntro C# Book
 
Arithmetic and logic operations in c
Arithmetic and logic operations in cArithmetic and logic operations in c
Arithmetic and logic operations in cVikas Dongre
 
Operators expressions-and-statements
Operators expressions-and-statementsOperators expressions-and-statements
Operators expressions-and-statementsCtOlaf
 
gate level modeling
gate level modelinggate level modeling
gate level modelingVandanaBR2
 

Ähnlich wie Verilog operators (20)

Matlab operators
Matlab operatorsMatlab operators
Matlab operators
 
C operators
C operators C operators
C operators
 
3.OPERATORS_MB.ppt .
3.OPERATORS_MB.ppt                      .3.OPERATORS_MB.ppt                      .
3.OPERATORS_MB.ppt .
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++
 
Csci101 lect09 vectorized_code
Csci101 lect09 vectorized_codeCsci101 lect09 vectorized_code
Csci101 lect09 vectorized_code
 
Python PCEP Logic Bit Operations
Python PCEP Logic Bit OperationsPython PCEP Logic Bit Operations
Python PCEP Logic Bit Operations
 
3306617
33066173306617
3306617
 
6 operators-in-c
6 operators-in-c6 operators-in-c
6 operators-in-c
 
6 operators-in-c
6 operators-in-c6 operators-in-c
6 operators-in-c
 
C++ Programming Basics.pptx
C++ Programming Basics.pptxC++ Programming Basics.pptx
C++ Programming Basics.pptx
 
8. operators
8. operators8. operators
8. operators
 
15 bitwise operators
15 bitwise operators15 bitwise operators
15 bitwise operators
 
Coding verilog
Coding verilogCoding verilog
Coding verilog
 
05 operators
05   operators05   operators
05 operators
 
4. operators in c programming by digital wave
4. operators in  c programming by digital wave4. operators in  c programming by digital wave
4. operators in c programming by digital wave
 
03. Operators Expressions and statements
03. Operators Expressions and statements03. Operators Expressions and statements
03. Operators Expressions and statements
 
Arithmetic and logic operations in c
Arithmetic and logic operations in cArithmetic and logic operations in c
Arithmetic and logic operations in c
 
Operators expressions-and-statements
Operators expressions-and-statementsOperators expressions-and-statements
Operators expressions-and-statements
 
gate level modeling
gate level modelinggate level modeling
gate level modeling
 
Oop using JAVA
Oop using JAVAOop using JAVA
Oop using JAVA
 

Mehr von Dr.YNM

Introduction to DSP.ppt
Introduction to DSP.pptIntroduction to DSP.ppt
Introduction to DSP.pptDr.YNM
 
Atmel.ppt
Atmel.pptAtmel.ppt
Atmel.pptDr.YNM
 
PIC Microcontrollers.ppt
PIC Microcontrollers.pptPIC Microcontrollers.ppt
PIC Microcontrollers.pptDr.YNM
 
Crystalstructure-.ppt
Crystalstructure-.pptCrystalstructure-.ppt
Crystalstructure-.pptDr.YNM
 
Basics of OS & RTOS.ppt
Basics of OS & RTOS.pptBasics of OS & RTOS.ppt
Basics of OS & RTOS.pptDr.YNM
 
Introducion to MSP430 Microcontroller.pptx
Introducion to MSP430 Microcontroller.pptxIntroducion to MSP430 Microcontroller.pptx
Introducion to MSP430 Microcontroller.pptxDr.YNM
 
Microcontroller-8051.ppt
Microcontroller-8051.pptMicrocontroller-8051.ppt
Microcontroller-8051.pptDr.YNM
 
Introduction to ASICs.pptx
Introduction to ASICs.pptxIntroduction to ASICs.pptx
Introduction to ASICs.pptxDr.YNM
 
VHDL-PRESENTATION.ppt
VHDL-PRESENTATION.pptVHDL-PRESENTATION.ppt
VHDL-PRESENTATION.pptDr.YNM
 
Basics of data communications.pptx
Basics of data communications.pptxBasics of data communications.pptx
Basics of data communications.pptxDr.YNM
 
CPLD & FPGA Architectures and applictionsplications.pptx
CPLD & FPGA Architectures and applictionsplications.pptxCPLD & FPGA Architectures and applictionsplications.pptx
CPLD & FPGA Architectures and applictionsplications.pptxDr.YNM
 
Transient response of RC , RL circuits with step input
Transient response of RC , RL circuits  with step inputTransient response of RC , RL circuits  with step input
Transient response of RC , RL circuits with step inputDr.YNM
 
CISC & RISC ARCHITECTURES
CISC & RISC ARCHITECTURESCISC & RISC ARCHITECTURES
CISC & RISC ARCHITECTURESDr.YNM
 
Lect 4 ARM PROCESSOR ARCHITECTURE
Lect 4 ARM PROCESSOR ARCHITECTURELect 4 ARM PROCESSOR ARCHITECTURE
Lect 4 ARM PROCESSOR ARCHITECTUREDr.YNM
 
Lect 3 ARM PROCESSOR ARCHITECTURE
Lect 3  ARM PROCESSOR ARCHITECTURE Lect 3  ARM PROCESSOR ARCHITECTURE
Lect 3 ARM PROCESSOR ARCHITECTURE Dr.YNM
 
Microprocessor Architecture 4
Microprocessor Architecture  4Microprocessor Architecture  4
Microprocessor Architecture 4Dr.YNM
 
Lect 2 ARM processor architecture
Lect 2 ARM processor architectureLect 2 ARM processor architecture
Lect 2 ARM processor architectureDr.YNM
 
Microprocessor Architecture-III
Microprocessor Architecture-IIIMicroprocessor Architecture-III
Microprocessor Architecture-IIIDr.YNM
 
LECT 1: ARM PROCESSORS
LECT 1: ARM PROCESSORSLECT 1: ARM PROCESSORS
LECT 1: ARM PROCESSORSDr.YNM
 
Microprocessor architecture II
Microprocessor architecture   IIMicroprocessor architecture   II
Microprocessor architecture IIDr.YNM
 

Mehr von Dr.YNM (20)

Introduction to DSP.ppt
Introduction to DSP.pptIntroduction to DSP.ppt
Introduction to DSP.ppt
 
Atmel.ppt
Atmel.pptAtmel.ppt
Atmel.ppt
 
PIC Microcontrollers.ppt
PIC Microcontrollers.pptPIC Microcontrollers.ppt
PIC Microcontrollers.ppt
 
Crystalstructure-.ppt
Crystalstructure-.pptCrystalstructure-.ppt
Crystalstructure-.ppt
 
Basics of OS & RTOS.ppt
Basics of OS & RTOS.pptBasics of OS & RTOS.ppt
Basics of OS & RTOS.ppt
 
Introducion to MSP430 Microcontroller.pptx
Introducion to MSP430 Microcontroller.pptxIntroducion to MSP430 Microcontroller.pptx
Introducion to MSP430 Microcontroller.pptx
 
Microcontroller-8051.ppt
Microcontroller-8051.pptMicrocontroller-8051.ppt
Microcontroller-8051.ppt
 
Introduction to ASICs.pptx
Introduction to ASICs.pptxIntroduction to ASICs.pptx
Introduction to ASICs.pptx
 
VHDL-PRESENTATION.ppt
VHDL-PRESENTATION.pptVHDL-PRESENTATION.ppt
VHDL-PRESENTATION.ppt
 
Basics of data communications.pptx
Basics of data communications.pptxBasics of data communications.pptx
Basics of data communications.pptx
 
CPLD & FPGA Architectures and applictionsplications.pptx
CPLD & FPGA Architectures and applictionsplications.pptxCPLD & FPGA Architectures and applictionsplications.pptx
CPLD & FPGA Architectures and applictionsplications.pptx
 
Transient response of RC , RL circuits with step input
Transient response of RC , RL circuits  with step inputTransient response of RC , RL circuits  with step input
Transient response of RC , RL circuits with step input
 
CISC & RISC ARCHITECTURES
CISC & RISC ARCHITECTURESCISC & RISC ARCHITECTURES
CISC & RISC ARCHITECTURES
 
Lect 4 ARM PROCESSOR ARCHITECTURE
Lect 4 ARM PROCESSOR ARCHITECTURELect 4 ARM PROCESSOR ARCHITECTURE
Lect 4 ARM PROCESSOR ARCHITECTURE
 
Lect 3 ARM PROCESSOR ARCHITECTURE
Lect 3  ARM PROCESSOR ARCHITECTURE Lect 3  ARM PROCESSOR ARCHITECTURE
Lect 3 ARM PROCESSOR ARCHITECTURE
 
Microprocessor Architecture 4
Microprocessor Architecture  4Microprocessor Architecture  4
Microprocessor Architecture 4
 
Lect 2 ARM processor architecture
Lect 2 ARM processor architectureLect 2 ARM processor architecture
Lect 2 ARM processor architecture
 
Microprocessor Architecture-III
Microprocessor Architecture-IIIMicroprocessor Architecture-III
Microprocessor Architecture-III
 
LECT 1: ARM PROCESSORS
LECT 1: ARM PROCESSORSLECT 1: ARM PROCESSORS
LECT 1: ARM PROCESSORS
 
Microprocessor architecture II
Microprocessor architecture   IIMicroprocessor architecture   II
Microprocessor architecture II
 

Kürzlich hochgeladen

(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 

Kürzlich hochgeladen (20)

(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 

Verilog operators

  • 1. Digital Design Using Verilog - For Absolute Beginners LECTURE6 : VERILOG OPERATORS
  • 2. Introduction • Normally the operators work on any specific data types or operands to give expected results. • As Verilog is mainly used to describe the hardware behavior and functioning, it supports a variety of pre-defined operators . • But it should be always remembered that not all the operands are synthesizable. •Some of these operators are similar to the operators used in the C programming language. •Each operator type is denoted by a symbol
  • 3. contd • The different types of Operators supported are • Assignment operator • Arithmetic operators • Logical operators • relational, equality operators • Bitwise operators • Reduction operators • Shift operators • Concatenation and Conditional etc.
  • 4. ASSIGNMENT OPERATOR • Verilog uses the equal sign (=) to denote an assignment. • The left-hand side (LHS) of the assignment is the target signal. The right-hand side (RHS) contains the input arguments and can contain both signals, constants, and operators. • Ex: Y = a & b; • F2 = 8’hAA; • F1 = A ; 23 June 2020 4yayavaram@yahoo.com
  • 5. • The most fundamental operators are Arithmetic operators. • Broadly there are two types of arithmetic operators. (i).Unary and (ii).Binary Unary Operators: A unary operator is an operator that takes a single operand in an expression or a statement. + : addition % : modulus - : subtraction ** : exponentiaion * : multiplication / : divide 23 June 2020 5yayavaram@yahoo.com ARITHMETIC OPERATORS
  • 6. contd Ex: +A ; - Y ; - (A+B) ; ** D Exponential D etc. • Binary Operators : A binary operator is an operator that operates on two operands and manipulates them to return a result. • Y = (A+B) * (B+C) • X = (A+B) / (C-D) • D =A + D : Addition operator surrounded by two operands 23 June 2020 6yayavaram@yahoo.com
  • 7. Illustration • module Arithmetic (A, B, Y1, Y2, Y3, Y4, Y5); input [2:0] A, B; output [3:0] Y1; output [4:0] Y3; output [2:0] Y2, Y4, Y5; reg [3:0] Y1; reg [4:0] Y3; reg [2:0] Y2, Y4, Y5; always @(A or B) begin Y1=A+B; //addition operation Y2=A-B; //subtraction operation Y3=A*B; //multiplication operation Y4=A/B; //division operation Y5=A%B; //modulus of A divided by B end endmodule 23 June 2020 7 yayavaram@yahoo.com
  • 8. % Modulus operator • The modulus operator is denoted by the symbol %. • For example A % B, gives the remainder when the first operand is divided by the second, and thus is zero when B divides A exactly. • The result of a modulus operation shall take the sign of the first operand. 23 June 2020 8yayavaram@yahoo.com
  • 9. Logical Operator • These operators deals with true or false logic . i.e the logical operators return either 0 or 1. • Logical comparison operators are used in conjuction with relational and equality operators . • These operators are widely used in if ; While statements. And, provide a means to perform multiple comparisons within a single expression. • ! : Logical negation. Ex : ! (A && B) && : Logical AND || : Logical OR Ex : A || B 23 June 2020 9yayavaram@yahoo.com
  • 10. contd • Logical operators produce 1-bit results. • The result of && is one if none of the operands is 0. • The result of || is 1 if at least one of the operands is non-zero. • The ! Operator complements its operand and produces 1 or a 0. If X or Z appears in an operand of the logical operand ,an X will be the result.The ! Operator has the highest precedence, followed by && and || . 23 June 2020 10yayavaram@yahoo.com
  • 11. Examples • Let A = 3’b101 ; B = 3’b000; C = 3’B01X • !A = 1b0 ; • !B = 1’b1 ; • !C = 1’Bx • A && B => 1’b 0 ; // since one operand is zero • B&&C=> 1’bX;// one operand is unknown • A || B => 1’b1 // one of the operands is non-zero • B || C => 1’bX 23 June 2020 11yayavaram@yahoo.com
  • 12. Example-2 • module ex_logical (A, B, C, D, E, F, Y); input [2:0] A, B, C, D, E, F; output Y; reg Y; always @ (A or B or C or D or E or F) begin if ((A= =B) && ((C>D) || !(E<F))) Y=1; else Y=0; end endmodule 23 June 2020 12yayavaram@yahoo.com
  • 13. Relational & Equality Operators • These operators are mainly used to compare data values. • = = Equality ; != Not equal(Inequality) • = = = : Case equality ; ! = = Case inequality. • >= Greater or equal ; <= Less than or equal • > Greater ; < Less • Here = = ; ! = ; = = = are the equality operators • Case equality is used to compare the values with x or z. 23 June 2020 13yayavaram@yahoo.com
  • 14. Example for Case Equality • Let A = 1011; B = 1011 A = =B ; The result is true; • Let A = 0110 ; B = 1011; A == B ; The result is false ,as they are not equal. • Suppose A= 101X ; B = 101X ; • A ==B ; The result is unknown x So, One has to use case Equality operator. In a case equality A = = = B ; The result is 1 (true). • Suppose A=101X & B= 011X.The the result will be False i.e 0. 23 June 2020 14yayavaram@yahoo.com
  • 15. Illustration • module ex_relational (A, B, Y1, Y2, Y3, Y4); input [2:0] A, B; output Y1, Y2, Y3, Y4; reg Y1, Y2, Y3, Y4; always @(A or B) begin Y1=A<B;//less than Y2=A<=B;//less than or equal to Y3=A>B;//greater than if (A>B) Y4=1; else Y4=0; end endmodule 23 June 2020 15yayavaram@yahoo.com
  • 16. Illustration-Equality operators • module ex_equality (a, b, y1, y2, y3); input [2:0] a,b; output y1,y2; output [2:0] y3; reg y1,y2; reg [2:0] y3; always @(a or b) begin y1= a= =b;// y1=1 if a equivalent to b y2=a!=b;//y2=1 if a not equivalent to b if (a= =b) // y3= a; else y3= b; end endmodule 23 June 2020 16yayavaram@yahoo.com
  • 17. Bitwise Operators • Verilog bitwise operators can be either unary or binary. Result is always the size of largest operand. • i.e the meaning is , logical bit-wise operators take two single or multiple operands on either side of the operator and return a single bit result. • The only exception is the NOT operator, which negates the single operand that follows. • Verilog does not have the equivalent of NAND or NOR operator, their function is implemented by negating the AND and OR operators. 23 June 2020 17yayavaram@yahoo.com
  • 18. contd • ~ : bitwise NOT(Invert) • & : bit wise AND • | : bitwise OR • ^ : bitwise Exclusive OR • ~ ^ : bitwise exclusive NOR • Bit wise operators operate on each bit and returns a value that is also a bit. 23 June 2020 18yayavaram@yahoo.com
  • 19. Bitwise Operators contd • If two operands are unequal ,the smaller one is left extended by adding zeros. • Ex : a = 4’b1001 and b = 3’b 101. To find a & b , the second operand is taken as b = 4’b0101 and then logical & operation is performed. a & b => 4’b0001 The size of the result is 4 bits . 23 June 2020 19yayavaram@yahoo.com
  • 20. Examples • assign a => 4’b1011 ; b=> 4’b1101 ; c => 4’b0111; • ~ a => 4’b 0100 ; ~b=> 4’b0010 ; ~c => 4’b1000; • a & b => 4’b1001 ; b & c => 4’b 0101 • a | b => 4’b1111 ; b | c => 4’b1111 • a ^ b => 4’b 0110 ; b ^ c => 4’b 1010 • a ^ ~b => 4’b 1001 ; b ^ ~ c => 4’b 0101 23 June 2020 20yayavaram@yahoo.com
  • 21. Example-2 • module ex_Bitwise (A, B, Y); input [6:0] A; input [5:0] B; output [6:0] Y; reg [6:0] Y; always @(A or B) begin Y(0)=A(0)&B(0); // binary AND Y(1)=A(1)|B(1); // binary OR Y(2)=!(A(2)&B(2)); // negated AND (NAND) Y(3)=!(A(3)|B(3)); // negated OR (NOR) Y(4)=A(4)^B(4); // binary XOR Y(5)=A(5)~^B(5); // binary XNOR Y(6)=!A(6); // unary negation end endmodule 23 June 2020 21yayavaram@yahoo.com
  • 22. Reduction Operators • Reduces a vector to a single bit value. i.e a multibit value is reduced to a single bit value. • Majority of the times this is a unary operator. • To say in terms of hardware , This reduction operator works like a multiple input bits logic gate,which accepts a single word operand and produces a single bit as output. • The operators are • & and ; ~ & not and(nand) ; | or ; ~ | not or (nor) • ^ x-or ; ~ ^ not or (x-nor) 23 June 2020 22yayavaram@yahoo.com
  • 23. Examples • For ex, in the ‘and’ gate for the Inputs 1011 the output is 0. • Similarly let us consider or gate as shown below. • So, these reduction operands are reducing a multibit operands into single bit operands. • s.23 June 2020 23yayavaram@yahoo.com
  • 24. Examples contd • Let us consider the x-or gate . • y = ^ A where A = 4’b0110 i.e y = 0 ^1^1^0 = 1 23 June 2020 24yayavaram@yahoo.com
  • 25. Example for Reduction Operator • module red_ex(a,b,c,y1,y2,y3); input a, b, c ; output y1,y2,y3 ; wire[7:0] a,b,c ; wire [7:0]y1,y2,y3 ; assign a=4’b0111; assign b=4’b0111; assign c=4’b0100; assign y1 = ^a // gives y1 = 1 assign y2 = &(a^b); //gives y2=0 assign y3 = ^a&^b; //gives y3 = 1 23 June 2020 25yayavaram@yahoo.com
  • 26. SHIFT OPERATORS • Generally ,the shift operators are used to shift the operand bits either left or right. • Shift operators require two operands. The operand before the operator contains data to be shifted and the operand after the operator contains the number of single bit shift operations to be performed. • Verilog has two types of shift operators . • i. Logical Shift and ii.Arithmetic shift operators. 23 June 2020 26yayavaram@yahoo.com
  • 27. • This shifting is done in two ways. Either Left shift or Right shift. • Logical Right shift operator is denoted by >> • Logical Left shift operator is <<. • In logical shift vacated positions are always filled with zero(0). • In terms of the operation right shift means divide by 2 also. • Similarly Left shift operation will result in multiply of the operand by 2. 23 June 2020 27yayavaram@yahoo.com contd
  • 28. Arithmetic Shift Operators • Right arithmetic shift is denoted by the symbol >>> • Left arithmetic shift is denoted by <<<. • In arithmetic shift: For signed numbers , the vacated position is filled with sign bit value(MSB bit) • For unsigned ,the vacated positions are filled with zero. 23 June 2020 28yayavaram@yahoo.com
  • 29. Code-Example • module ex_shift (a, y1, y2); input [7:0] a; output [7:0] y1, y2; parameter b=3; reg [7:0] y1, y2; always @(a) begin y1=a<<b; //logical shift left y2=a>>b; //logical shift right end • endmodule 23 June 2020 29yayavaram@yahoo.com
  • 30. Concatenation Operator{,} • The concatenation operator "{ , }" combines or (concatenates) the bits of two or more data objects. • The objects may be scalar (single bit) or vectored (muliple bit). • Mutiple concatenations may be performed with a constant prefix and is known as replication. • For ex: By concatenating two 4-bit operands, an 8-bit operand is formed. • Remember it is not direct arithmetic addition. • Ex: Let A= 4’b1011; B=4’b 1010; assign y = {a,b} gives y=> 8b’10111010 23 June 2020 30yayavaram@yahoo.com
  • 31. Replicate Operator • It replicates the operand for a specified number of times.( or copied specified number of times). • For ex: assign y = {3{3’b110}} results in • y = 9’b110110110 23 June 2020 31yayavaram@yahoo.com
  • 32. Conditional Operator(?) • An expression using conditional operator evaluates the logical expression before the "?". • If the expression is true then the expression before the colon (:) is evaluated and assigned to the output. • If the logical expression is false then the expression after the colon is evaluated and assigned to the output. 23 June 2020 32yayavaram@yahoo.com
  • 33. Example code • To understand the Conditional operator lets consider the 2:1 Mux example. Ex: module mymux2_1(A,B,S,Y); output Y; input A,B,S; assign Y= S ? B:A; endmodule Note: In the above ,first the ‘S’ is tested .If it is true,then Y= B else Y = A 23 June 2020 33yayavaram@yahoo.com
  • 34. The Conclusion 23 June 2020 34yayavaram@yahoo.com

Hinweis der Redaktion

  1. If the value of S is 1 ,then Y= B other wise Y= A
  2. If the value of S is 1 ,then Y= B other wise Y= A