SlideShare a Scribd company logo
VHDL 360©

by: Mohamed Samy
  Samer El-Saadany
Copyrights
Copyright © 2010/2011 to authors. All rights reserved
• All content in this presentation, including charts, data, artwork and
  logos (from here on, "the Content"), is the property of Mohamed
  Samy and Samer El-Saadany or the corresponding owners,
  depending on the circumstances of publication, and is protected by
  national and international copyright laws.
• Authors are not personally liable for your usage of the Content that
  entailed casual or indirect destruction of anything or actions entailed
  to information profit loss or other losses.
• Users are granted to access, display, download and print portions of
  this presentation, solely for their own personal non-commercial use,
  provided that all proprietary notices are kept intact.
• Product names and trademarks mentioned in this presentation
  belong to their respective owners.


                                 VHDL 360 ©                    2
Module 3 (Continued)

 Data Types and Operators
Objective
• Introducing Data Types & Operators
• Skills gained:
  – Familiarity with data types
  – More on Expressions & Operators
  – Modeling Memories




                    VHDL 360 ©         4
Outline
• Expressions & Operators
• Aggregate
• Attributes




                  VHDL 360 ©   5
Operators
   • We have discussed some operators in Module 1*
   • Operators are subprograms defined for specific data type(s)
        –    Operators of the standard types (eg. bit, integer,…) are defined in "STD" library;
             in "standard" package. This package is visible by default to all VHDL design
             units.

Example 1:

         res <= (a and not(b)) or (not(a) and b);

   • Parentheses are used for readability and to control the association
     of operators and operands
   • Unless parentheses are used, the operators with the highest
     precedence are applied first




*Module 1: Create your first model for a simple logic circuit
                                               VHDL 360 ©                           6
Operators Precedence
 • Operators’ precedence are in the following descending order:
     –   Miscellaneous operators    **, abs, not
     –   Multiplication operators    *, /, mod, rem
     –   Sign operator               +, -
     –   Addition operators          +, -, &
     –   Shift operators             sll, srl, sla, sra, rol, ror
     –   Relational operators         =, /=, <, <=, >, >=, ?=, ?/=, ?<, ?<=, ?>, ?>=
     –   Logical operators            and, or, nand, nor, xor, xnor
     –   Condition operator           ??
 • Operators of the same precedence are applied from left to right




Items in blue were added in VHDL 2008


                                         VHDL 360 ©                              7
Logical Operators
Operation                                                     Package               Comments
bit <= bit AND bit;                                           Standard              Similarly NAND, OR, NOR,
bit_vector <= bit_vector AND bit_vector;                                            XOR…etc
std_logic <= std_logic AND std_logic;                         ieee.std_logic_1164   Similarly NAND, OR, NOR,
std_logic_vector <= std_logic _vector AND std_logic_vector;                         XOR…etc


std_logic_vector <= std_logic AND std_logic_vector;           ieee.std_logic_1164   VHDL 2008 standard*
                                                                                    Similarly NAND, OR, NOR,
                                                                                    XOR…etc




• When the operands are arrays they must have the same size
• Operations on arrays are done starting from the left towards the right




 *Not yet supported by all tools in the market

                                                       VHDL 360 ©                                  8
Addition Operators
     Operation*                                                       Package                     Comments
     integer<= integer +/- integer                                    Standard
     std_logic_vector <= std_logic_vector +/- integer                 ieee.std_logic_unsigned     Unsigned addition/subtraction
     std_logic_vector <= std_logic_vector +/- std_logic_vector        ieee.std_logic_signed       Signed addition/subtraction
     std_logic_vector <= std_logic_vector +/- std_logic


     std_logic_vector <= std_logic_vector +/- natural                 ieee.numeric_std_unsigned   VHDL 2008 standard*
     std_logic_vector <= std_logic_vector +/- std_logic_vector        ieee.numeric_std_signed
     std_logic_vector <= std_logic_vector +/- std_logic


     std_logic_vector <= std_logic_vector & std_logic                 Standard                    Operands can be of different size,
     std_logic_vector <= std_logic & std_logic_vector                                             result’s size will be the sum of both
     std_logic_vector <= std_logic_vector & std_logic_vector                                      sizes


Example 2:                                               Example 3:
  -- A: 3 bits                                                 cin     :   in std_logic;
  -- B: 5 bits                                                 a, b    :   in std_logic_vector(7 downto 0);
  -- C: 8 bits                                                 cout    :   out std_logic;
  C <= B & A;                                                  y       :   out std_logic_vector(7 downto 0));
        B                        A
                                                               signal result : std_logic_vector(8 downto 0);
                      &

                           A <= B & C                          result <= ('0' & a) + ('0' & b) + cin;
                                                               cout <= result (8);
                      C                                        y <= result (7 downto 0);
                B            A
*Addition operators are Commutative
*Not yet supported by all tools in the market                         VHDL 360 ©                                         9
Reference page

                         Relational Operators
 Operator        Description                       Operand Types                                    Result Type
 =               Equality                          any type but file type or protected type         Boolean
 /=              Inequality

 <               Smaller than                      scalar or discrete array types                   Boolean
 <=              Smaller than or equal
 >               Greater than
 >=              Greater than or equal

 ?=              Matching equality (VHDL 2008)*    bit or std_ulogic or any one-dimensional array   same as operand
 ?/=             Matching inequality (VHDL 2008)   type whose element type is BIT or STD_ULOGIC     type or the element
                                                                                                    Type of the
                                                                                                    operands

 ?<              Matching ordering (VHDL 2008)     BIT or                                           same as operand
 ?<=                                               STD_ULOGIC                                       type
 ?>
 ?>=

• Operations on arrays are done starting from the left towards the right
• When comparing arrays; always ensure that the arrays are the same size
• Notice the return type of the matching operators

*Not yet supported by all tools in the market          VHDL 360 ©                                     10
Reference page

                                Shift Operators
Operator   Description                 Left Operand Type                      Right Operand Type   Result Type         Package



sll        Shift left logical (fill    Any one-dimensional array type         Integer              Same as left type   Standard
           right vacant bits           with elements of type bit or boolean
           with 0)

srl        Shift right logical (fill   same as above                          Integer              Same as left type   Standard
           left vacated bits
           with 0)

sla        Shift left arithmetic       same as above                          Integer              Same as left type   Standard
           (fill right vacated
           bits with rightmost
           bit)

sra        Shift right arithmetic      same as above                          Integer              Same as left type   Standard
           (fill left vacated bits
           with leftmost bit)


rol        Rotate left (circular)      same as above                          Integer              Same as left type   Standard


ror        Rotate right                same as above                          Integer              Same as left type   Standard
           (circular)



                                                                  VHDL 360 ©                                     11
Reference page

                                  Shift Operators
Operator    Description              Left Operand Type   Right Operand      Result Type            Package
                                                         Type


SHL         Shift left               std_logic_vector    std_logic_vector   std_logic_vector       ieee.std_logic_unsigned
                                                                                                   ieee.std_logic_signed

SHR         Shift right              std_logic_vector    std_logic_vector   std_logic_vector       ieee.std_logic_unsigned
                                                                                                   ieee.std_logic_signed

sll         Shift left logical       std_logic_vector    Integer            std_logic_vector       ieee.std_logic_1164*


srl         Shift right logical      std_logic_vector    Integer            std_logic_vector       ieee.std_logic_1164*


rol         Rotate left (circular)   std_logic_vector    Integer            std_logic_vector       ieee.std_logic_1164*


ror         Rotate right             std_logic_vector    Integer            std_logic_vector       ieee.std_logic_1164*
            (circular)




* VHDL 2008, Not yet supported by all tools              VHDL 360 ©                                 12
Reference page

                        Shift Operators
• The left operand is array to be shifted and the right operand is
  the number of shifts (must be integer)

Example 4:
 signal A: bit_vector := "101001";

 A   <=   A   sll   2   -- A = "100100"
 A   <=   A   srl   2   -- A = "001010"
 A   <=   A   sla   2   -- A = "100111"
 A   <=   A   sra   2   -- A = "111010"
 A   <=   A   rol   2   -- A = "100110"
 A   <=   A   ror   2   -- A = "011010"




                                          VHDL 360 ©          13
Reference page

           Multiplication Operators
Operator   Description      Left Operand Type                  Right Operand Type      Result Type



*          Multiplication   Any integer                        Same type               Same type

                            floating-point type                Same type               Same type

/          Division         Any integer                        Same type               Same type

                            floating-point type                Same type               Same type

mod        Modulus          Any integer type                   Same type               Same type

rem        Remainder        Any integer type                   Same type               Same type




                                                  VHDL 360 ©                             14
Reference page

            Multiplication Operators
                    REM                                                        MOD
 Defined using the equation:                              Defined using the equation:
 A = (A/B)*B + (A rem B)                                  A = B*N + (A mod B)
 Where:                                                   Where:
     A/B is an integer                                          N is an integer
     (A rem B) has the same sign of A                           (A mod B) has the same sign of B
     Absolute value of (A rem B) < Absolute value of B          Absolute value of (A mod B) < Absolute value of B


Example 5                                                 Example 6
  5 rem 3 = 2                                                  5 mod 3 = 2
  (-5) rem 3 = -2                                              (-5) mod 3 = 1
  (-5) rem (-3) = -2                                           (-5) mod (-3) = -2
  5 rem (-3) = 2                                               5 mod (-3) = -1
  11 rem 4 = 3                                                 9 mod 4 = 1
  (-11) rem 4 = -3                                             7 mod (-4) = -1




                                                  VHDL 360 ©                                     15
Reference page

           Miscellaneous Operators
Operator    Description           Left Operand Type      Right Operand     Result Type
                                                             Type


**          Exponentiation        Integer type           Integer type      Same as left

                                  floating-point type                      Same as left

abs         Absolute value        Any numeric type                         Same type

not         Logical negation      Any bit or Boolean type                  Same type

Example 7:
 x    <=   5**5           -- ok
 y    <=   0.5**3         -- ok
 x    <=   4**0.5         -- illegal (the return type is not integer)
 y    <=   0.5**(-2)      -- ok
 Y    <=   5**(-2)        -- illegal (the return type is not integer)

                                         VHDL 360 ©                           16
Aggregate
• Provides an easy way of assigning objects of composite types

Example 8:
Signal data_bus : std_logic_vector(15 downto 0);

data_bus <= (15 downto 8 => '0' , others => '1');
--data_bus(1), data_bus(4), data_bus(7) are '1' while data_bus(2), data_bus(3) are '0';others are 'Z'
data_bus <= (1 | 4 | 7 => '1', 2 | 3 => '0', others => 'Z');

data_bus <= (others => '1');               -- fill data_bus with ones

data_bus <= ("0100", others => '1'); *    --                    data_bus <= "0100_1111_1111_1111"
(carry_out, sum) <= ('0' & a) + ('0' & b); *                     -- target of an assignment


data_bus <= B"0001_1111_0110_0000"; -- _ for readability
data_bus <= X"1F05"; -- X stands for hexadecimal thus data_bus              <= "0001_1111_0000_0101"




 * VHDL 2008
                                              VHDL 360 ©                             17
Attributes (')
• Attribute: a characteristic that something has
  – used to return information about a signal, variable or a data type
  – consists of an apostrophe “tick” mark (') followed by the attribute
    name
• Predefined Type Attributes
  – 'left, 'right, 'low, 'high, 'image, …
• Predefined Array Attributes
  – 'left, 'right, 'low, 'high, 'range, 'length, …
• Predefined Signal Attributes
  – 'event, …




                                  VHDL 360 ©                  18
Attributes (')
Example 9:
 ARCHITECTURE examp OF attrs IS
   Type myInt is range 0 to 15;    Type states is (red, yellow, green);
   Type word is array (15 downto 0) of std_logic;
   Signal count: integer;     signal mySig: myInt;
   signal state : states;
 BEGIN
   process
     begin
        mySig <= myInt'left; count <= word'left; state <= states'left;
        wait for 10 ns;
        mySig <= myInt'right; count <= word'right; state <= states'right;
        wait for 10 ns;
        mySig <= myInt'low; count <= word'low; state <= states'low;
        wait for 10 ns;
        mySig <= myInt'high; count <= word'high; state <= states'high;
        wait for 10 ns;
        count <= word'length;
        wait;
    end process;
 END ARCHITECTURE examp;




                                         VHDL 360 ©                         19
Example 10:
                         Knight Rider
  LIBRARY ieee;
  USE ieee.std_logic_1164.all;
  ENTITY knight_rider IS
    port(clk, rst, enable: in std_logic;
         knight: out std_logic_vector(7 downto 0));
  END ENTITY;
  ARCHITECTURE behave OF knight_rider IS
    signal temp: std_logic_vector(knight'range);
    signal count: integer range knight'low to knight'high;
    signal direction: std_logic;
  BEGIN
    process(clk)
    begin
     if rising_edge(clk) then
       if rst = '1' then
         temp <= (knight'left => '1', others => '0');
         direction <= '1';
         count <= 0;
         …


                                    VHDL 360 ©               20
Knight Rider
 …
 elsif enable = '1' then
   if direction = '0' then
     temp <= temp(knight'left-1 downto knight'right) & temp (knight'left);
   else
     temp <= temp(knight'right) & temp(knight'left downto knight'right+1);
   end if;

    if count = knight'length-2 then
      count <= 0;
      direction <= not direction;
    else
      count <= count +1;
    end if;
  end if;
end if;
end process;
knight <= temp;
END ARCHITECTURE;


                                  VHDL 360 ©                    21
Contacts
• You can contact us at:
  – http://www.embedded-tips.blogspot.com/




                     VHDL 360 ©         22

More Related Content

What's hot (20)

PDF
Basic structures in vhdl
Raj Mohan
 
DOCX
VHDL CODES
OmkarDarekar6
 
PPTX
Basics of Vhdl
Atchyuth Sonti
 
PPT
VHDL - Enumerated Types (Part 3)
Abhilash Nair
 
PPTX
Create your first model for a simple logic circuit
Mohamed Samy
 
PPT
Short.course.introduction.to.vhdl for beginners
Ravi Sony
 
PPT
VHDL Entity
Ramasubbu .P
 
PPTX
Verilog presentation final
Ankur Gupta
 
PDF
Verilog HDL Training Course
Paul Laskowski
 
PPTX
Vhdl programming
Yogesh Mashalkar
 
PPT
VHDL Subprograms and Packages
Ramasubbu .P
 
PPTX
Verilog overview
posdege
 
PPTX
Verilogspk1
supriya kurlekar
 
PPT
Crash course in verilog
Pantech ProLabs India Pvt Ltd
 
PDF
INTRODUCTION TO VHDL
karthikpunuru
 
PPTX
Modeling FSMs
Mohamed Samy
 
PPTX
Modules and ports in Verilog HDL
anand hd
 
PDF
Verilog tutorial
Abhiraj Bohra
 
DOCX
Vhdl
Neeraj Gupta
 
Basic structures in vhdl
Raj Mohan
 
VHDL CODES
OmkarDarekar6
 
Basics of Vhdl
Atchyuth Sonti
 
VHDL - Enumerated Types (Part 3)
Abhilash Nair
 
Create your first model for a simple logic circuit
Mohamed Samy
 
Short.course.introduction.to.vhdl for beginners
Ravi Sony
 
VHDL Entity
Ramasubbu .P
 
Verilog presentation final
Ankur Gupta
 
Verilog HDL Training Course
Paul Laskowski
 
Vhdl programming
Yogesh Mashalkar
 
VHDL Subprograms and Packages
Ramasubbu .P
 
Verilog overview
posdege
 
Verilogspk1
supriya kurlekar
 
Crash course in verilog
Pantech ProLabs India Pvt Ltd
 
INTRODUCTION TO VHDL
karthikpunuru
 
Modeling FSMs
Mohamed Samy
 
Modules and ports in Verilog HDL
anand hd
 
Verilog tutorial
Abhiraj Bohra
 

Similar to Data types and Operators Continued (20)

PPTX
a verilog presentation for deep concept understa
SRAJALDWIVEDI1
 
PPTX
Experiment 1- UCS 704_ESD engineering money waste
kartikgupta886034
 
PPTX
Verilog Final Probe'22.pptx
SyedAzim6
 
PPT
Verilog tutorial
Maryala Srinivas
 
PPTX
INTERN VLSI 1.pptx INTERN VLSI 1.pptx ppt
nandithad23
 
PPTX
Data types and Operators
Mohamed Samy
 
PPT
verilog_1.ppt
HaleNurKumcuoglu
 
PPTX
systemverilog and veriog presentation
KhushiV8
 
PPTX
VHDL for beginners in Printed Circuit Board designing
merlynsheena
 
PDF
Java Review
pdgeorge
 
PPTX
systemverilog and veriog presentation
KhushiV8
 
PDF
Verilog HDL
HasmukhPKoringa
 
PPTX
Java platform
Visithan
 
PPTX
UNIT-I.pptx of subject in engineering bla bla bla
SEN150VAIBHAVWAKHARE
 
PPTX
Dica ii chapter slides
SIVA NAGENDRA REDDY
 
PPTX
Verilog
Mohamed Rayan
 
PDF
Session 02 _rtl_design_with_vhdl 101
Mahmoud Abdellatif
 
DOCX
Prilimanary Concepts of VHDL by Dr.R.Prakash Rao
rachurivlsi
 
PPT
Introduction to VHDL language VHDL_Intro.ppt
DrVikasMahor
 
PPTX
the-vhsic-.pptx
jpradha86
 
a verilog presentation for deep concept understa
SRAJALDWIVEDI1
 
Experiment 1- UCS 704_ESD engineering money waste
kartikgupta886034
 
Verilog Final Probe'22.pptx
SyedAzim6
 
Verilog tutorial
Maryala Srinivas
 
INTERN VLSI 1.pptx INTERN VLSI 1.pptx ppt
nandithad23
 
Data types and Operators
Mohamed Samy
 
verilog_1.ppt
HaleNurKumcuoglu
 
systemverilog and veriog presentation
KhushiV8
 
VHDL for beginners in Printed Circuit Board designing
merlynsheena
 
Java Review
pdgeorge
 
systemverilog and veriog presentation
KhushiV8
 
Verilog HDL
HasmukhPKoringa
 
Java platform
Visithan
 
UNIT-I.pptx of subject in engineering bla bla bla
SEN150VAIBHAVWAKHARE
 
Dica ii chapter slides
SIVA NAGENDRA REDDY
 
Verilog
Mohamed Rayan
 
Session 02 _rtl_design_with_vhdl 101
Mahmoud Abdellatif
 
Prilimanary Concepts of VHDL by Dr.R.Prakash Rao
rachurivlsi
 
Introduction to VHDL language VHDL_Intro.ppt
DrVikasMahor
 
the-vhsic-.pptx
jpradha86
 
Ad

Recently uploaded (20)

PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
PPTX
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
PPTX
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PPTX
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
PDF
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
PDF
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PPTX
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
PDF
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
PPTX
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PDF
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
PPT
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
Dimensions of Societal Planning in Commonism
StefanMz
 
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
Ad

Data types and Operators Continued

  • 1. VHDL 360© by: Mohamed Samy Samer El-Saadany
  • 2. Copyrights Copyright © 2010/2011 to authors. All rights reserved • All content in this presentation, including charts, data, artwork and logos (from here on, "the Content"), is the property of Mohamed Samy and Samer El-Saadany or the corresponding owners, depending on the circumstances of publication, and is protected by national and international copyright laws. • Authors are not personally liable for your usage of the Content that entailed casual or indirect destruction of anything or actions entailed to information profit loss or other losses. • Users are granted to access, display, download and print portions of this presentation, solely for their own personal non-commercial use, provided that all proprietary notices are kept intact. • Product names and trademarks mentioned in this presentation belong to their respective owners. VHDL 360 © 2
  • 3. Module 3 (Continued) Data Types and Operators
  • 4. Objective • Introducing Data Types & Operators • Skills gained: – Familiarity with data types – More on Expressions & Operators – Modeling Memories VHDL 360 © 4
  • 5. Outline • Expressions & Operators • Aggregate • Attributes VHDL 360 © 5
  • 6. Operators • We have discussed some operators in Module 1* • Operators are subprograms defined for specific data type(s) – Operators of the standard types (eg. bit, integer,…) are defined in "STD" library; in "standard" package. This package is visible by default to all VHDL design units. Example 1: res <= (a and not(b)) or (not(a) and b); • Parentheses are used for readability and to control the association of operators and operands • Unless parentheses are used, the operators with the highest precedence are applied first *Module 1: Create your first model for a simple logic circuit VHDL 360 © 6
  • 7. Operators Precedence • Operators’ precedence are in the following descending order: – Miscellaneous operators **, abs, not – Multiplication operators *, /, mod, rem – Sign operator +, - – Addition operators +, -, & – Shift operators sll, srl, sla, sra, rol, ror – Relational operators =, /=, <, <=, >, >=, ?=, ?/=, ?<, ?<=, ?>, ?>= – Logical operators and, or, nand, nor, xor, xnor – Condition operator ?? • Operators of the same precedence are applied from left to right Items in blue were added in VHDL 2008 VHDL 360 © 7
  • 8. Logical Operators Operation Package Comments bit <= bit AND bit; Standard Similarly NAND, OR, NOR, bit_vector <= bit_vector AND bit_vector; XOR…etc std_logic <= std_logic AND std_logic; ieee.std_logic_1164 Similarly NAND, OR, NOR, std_logic_vector <= std_logic _vector AND std_logic_vector; XOR…etc std_logic_vector <= std_logic AND std_logic_vector; ieee.std_logic_1164 VHDL 2008 standard* Similarly NAND, OR, NOR, XOR…etc • When the operands are arrays they must have the same size • Operations on arrays are done starting from the left towards the right *Not yet supported by all tools in the market VHDL 360 © 8
  • 9. Addition Operators Operation* Package Comments integer<= integer +/- integer Standard std_logic_vector <= std_logic_vector +/- integer ieee.std_logic_unsigned Unsigned addition/subtraction std_logic_vector <= std_logic_vector +/- std_logic_vector ieee.std_logic_signed Signed addition/subtraction std_logic_vector <= std_logic_vector +/- std_logic std_logic_vector <= std_logic_vector +/- natural ieee.numeric_std_unsigned VHDL 2008 standard* std_logic_vector <= std_logic_vector +/- std_logic_vector ieee.numeric_std_signed std_logic_vector <= std_logic_vector +/- std_logic std_logic_vector <= std_logic_vector & std_logic Standard Operands can be of different size, std_logic_vector <= std_logic & std_logic_vector result’s size will be the sum of both std_logic_vector <= std_logic_vector & std_logic_vector sizes Example 2: Example 3: -- A: 3 bits cin : in std_logic; -- B: 5 bits a, b : in std_logic_vector(7 downto 0); -- C: 8 bits cout : out std_logic; C <= B & A; y : out std_logic_vector(7 downto 0)); B A signal result : std_logic_vector(8 downto 0); & A <= B & C result <= ('0' & a) + ('0' & b) + cin; cout <= result (8); C y <= result (7 downto 0); B A *Addition operators are Commutative *Not yet supported by all tools in the market VHDL 360 © 9
  • 10. Reference page Relational Operators Operator Description Operand Types Result Type = Equality any type but file type or protected type Boolean /= Inequality < Smaller than scalar or discrete array types Boolean <= Smaller than or equal > Greater than >= Greater than or equal ?= Matching equality (VHDL 2008)* bit or std_ulogic or any one-dimensional array same as operand ?/= Matching inequality (VHDL 2008) type whose element type is BIT or STD_ULOGIC type or the element Type of the operands ?< Matching ordering (VHDL 2008) BIT or same as operand ?<= STD_ULOGIC type ?> ?>= • Operations on arrays are done starting from the left towards the right • When comparing arrays; always ensure that the arrays are the same size • Notice the return type of the matching operators *Not yet supported by all tools in the market VHDL 360 © 10
  • 11. Reference page Shift Operators Operator Description Left Operand Type Right Operand Type Result Type Package sll Shift left logical (fill Any one-dimensional array type Integer Same as left type Standard right vacant bits with elements of type bit or boolean with 0) srl Shift right logical (fill same as above Integer Same as left type Standard left vacated bits with 0) sla Shift left arithmetic same as above Integer Same as left type Standard (fill right vacated bits with rightmost bit) sra Shift right arithmetic same as above Integer Same as left type Standard (fill left vacated bits with leftmost bit) rol Rotate left (circular) same as above Integer Same as left type Standard ror Rotate right same as above Integer Same as left type Standard (circular) VHDL 360 © 11
  • 12. Reference page Shift Operators Operator Description Left Operand Type Right Operand Result Type Package Type SHL Shift left std_logic_vector std_logic_vector std_logic_vector ieee.std_logic_unsigned ieee.std_logic_signed SHR Shift right std_logic_vector std_logic_vector std_logic_vector ieee.std_logic_unsigned ieee.std_logic_signed sll Shift left logical std_logic_vector Integer std_logic_vector ieee.std_logic_1164* srl Shift right logical std_logic_vector Integer std_logic_vector ieee.std_logic_1164* rol Rotate left (circular) std_logic_vector Integer std_logic_vector ieee.std_logic_1164* ror Rotate right std_logic_vector Integer std_logic_vector ieee.std_logic_1164* (circular) * VHDL 2008, Not yet supported by all tools VHDL 360 © 12
  • 13. Reference page Shift Operators • The left operand is array to be shifted and the right operand is the number of shifts (must be integer) Example 4: signal A: bit_vector := "101001"; A <= A sll 2 -- A = "100100" A <= A srl 2 -- A = "001010" A <= A sla 2 -- A = "100111" A <= A sra 2 -- A = "111010" A <= A rol 2 -- A = "100110" A <= A ror 2 -- A = "011010" VHDL 360 © 13
  • 14. Reference page Multiplication Operators Operator Description Left Operand Type Right Operand Type Result Type * Multiplication Any integer Same type Same type floating-point type Same type Same type / Division Any integer Same type Same type floating-point type Same type Same type mod Modulus Any integer type Same type Same type rem Remainder Any integer type Same type Same type VHDL 360 © 14
  • 15. Reference page Multiplication Operators REM MOD Defined using the equation: Defined using the equation: A = (A/B)*B + (A rem B) A = B*N + (A mod B) Where: Where: A/B is an integer N is an integer (A rem B) has the same sign of A (A mod B) has the same sign of B Absolute value of (A rem B) < Absolute value of B Absolute value of (A mod B) < Absolute value of B Example 5 Example 6 5 rem 3 = 2 5 mod 3 = 2 (-5) rem 3 = -2 (-5) mod 3 = 1 (-5) rem (-3) = -2 (-5) mod (-3) = -2 5 rem (-3) = 2 5 mod (-3) = -1 11 rem 4 = 3 9 mod 4 = 1 (-11) rem 4 = -3 7 mod (-4) = -1 VHDL 360 © 15
  • 16. Reference page Miscellaneous Operators Operator Description Left Operand Type Right Operand Result Type Type ** Exponentiation Integer type Integer type Same as left floating-point type Same as left abs Absolute value Any numeric type Same type not Logical negation Any bit or Boolean type Same type Example 7: x <= 5**5 -- ok y <= 0.5**3 -- ok x <= 4**0.5 -- illegal (the return type is not integer) y <= 0.5**(-2) -- ok Y <= 5**(-2) -- illegal (the return type is not integer) VHDL 360 © 16
  • 17. Aggregate • Provides an easy way of assigning objects of composite types Example 8: Signal data_bus : std_logic_vector(15 downto 0); data_bus <= (15 downto 8 => '0' , others => '1'); --data_bus(1), data_bus(4), data_bus(7) are '1' while data_bus(2), data_bus(3) are '0';others are 'Z' data_bus <= (1 | 4 | 7 => '1', 2 | 3 => '0', others => 'Z'); data_bus <= (others => '1'); -- fill data_bus with ones data_bus <= ("0100", others => '1'); * -- data_bus <= "0100_1111_1111_1111" (carry_out, sum) <= ('0' & a) + ('0' & b); * -- target of an assignment data_bus <= B"0001_1111_0110_0000"; -- _ for readability data_bus <= X"1F05"; -- X stands for hexadecimal thus data_bus <= "0001_1111_0000_0101" * VHDL 2008 VHDL 360 © 17
  • 18. Attributes (') • Attribute: a characteristic that something has – used to return information about a signal, variable or a data type – consists of an apostrophe “tick” mark (') followed by the attribute name • Predefined Type Attributes – 'left, 'right, 'low, 'high, 'image, … • Predefined Array Attributes – 'left, 'right, 'low, 'high, 'range, 'length, … • Predefined Signal Attributes – 'event, … VHDL 360 © 18
  • 19. Attributes (') Example 9: ARCHITECTURE examp OF attrs IS Type myInt is range 0 to 15; Type states is (red, yellow, green); Type word is array (15 downto 0) of std_logic; Signal count: integer; signal mySig: myInt; signal state : states; BEGIN process begin mySig <= myInt'left; count <= word'left; state <= states'left; wait for 10 ns; mySig <= myInt'right; count <= word'right; state <= states'right; wait for 10 ns; mySig <= myInt'low; count <= word'low; state <= states'low; wait for 10 ns; mySig <= myInt'high; count <= word'high; state <= states'high; wait for 10 ns; count <= word'length; wait; end process; END ARCHITECTURE examp; VHDL 360 © 19
  • 20. Example 10: Knight Rider LIBRARY ieee; USE ieee.std_logic_1164.all; ENTITY knight_rider IS port(clk, rst, enable: in std_logic; knight: out std_logic_vector(7 downto 0)); END ENTITY; ARCHITECTURE behave OF knight_rider IS signal temp: std_logic_vector(knight'range); signal count: integer range knight'low to knight'high; signal direction: std_logic; BEGIN process(clk) begin if rising_edge(clk) then if rst = '1' then temp <= (knight'left => '1', others => '0'); direction <= '1'; count <= 0; … VHDL 360 © 20
  • 21. Knight Rider … elsif enable = '1' then if direction = '0' then temp <= temp(knight'left-1 downto knight'right) & temp (knight'left); else temp <= temp(knight'right) & temp(knight'left downto knight'right+1); end if; if count = knight'length-2 then count <= 0; direction <= not direction; else count <= count +1; end if; end if; end if; end process; knight <= temp; END ARCHITECTURE; VHDL 360 © 21
  • 22. Contacts • You can contact us at: – http://www.embedded-tips.blogspot.com/ VHDL 360 © 22