basic language constructs of vhdlgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 basic...

59
1 Basic Language Constructs of VHDL VHDL Unit 2 RTL H d Ch t 3 3rd Part Digital Electronics RTL Hardware Design by P. Chu Chapter 3 Fall 2008

Upload: others

Post on 06-Jul-2020

7 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

1

Basic Language Constructs of VHDLVHDLUnit 2

RTL H dCh t 3

3rd PartDigital Electronics

RTL Hardware Design by P. Chu

Chapter 3

Fall 2008

Page 2: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

RTL Hardware Design by P

Chapter 3

2

Outline

Design by P. Chu

Outline

1 Basic VHDL program1. Basic VHDL program2. Lexical elements and program format3 Objects3. Objects4. Data type and operators

Page 3: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

3

1. Basic VHDL program

RTL H dCh t 3 RTL Hardware Design by P. Chu

Chapter 3

Page 4: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

Design unit RTL Hardware Design by P

Chapter 3

4

Design unit Design by P. Chu

• Building blocks in a VHDL program• Each design unit is analyzed and stored g y

independently• Types of design unit:yp g▫ entity declaration▫ architecture body▫ package declaration▫ package body

fi ti▫ configuration

Page 5: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

Entity declarationEntity declaration

• Simplified syntax

RTL Hardware Design by P. Chu Chapter 3

5

Page 6: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

• mode:• mode:▫ in: flow into the circuit▫ out: flow out of the circuitout: flow out of the circuit▫ inout: bi-directional

• E.g.E.g.

RTL Hardware Design by P. Chu Chapter 3

6

Page 7: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

• A common mistake with mode

RTL Hardware Design by P. Chu Chapter 3

7

Page 8: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

• Fix: use an internal signal

RTL Hardware Design by P. Chu Chapter 3

8

Page 9: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

Architecture bodyArchitecture body• Simplified syntaxp y

• An entity declaration can be associated with multiple architecture bodies

RTL Hardware Design by P. Chu Chapter 3

9

p

Page 10: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

E.g.

RTL Hardware Design by P. Chu Chapter 3

10

Page 11: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

RTL Hardware Design by P

Chapter 3

11

Other design units

Design by P. Chu

Other design units• Package declaration/body:• Package declaration/body:▫ collection of commonly used items, such as data

t b d ttypes, subprograms and components• Configuration:

if hi h hi b d i b b d ▫ specify which architecture body is to be bound with the entity declaration

Page 12: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

VHDL Library RTL Hardware Design by P

Chapter 3

12

VHDL Library Design by P. Chu

• A place to store the analyzed design units• Normally mapped to a directory in host y pp y

computer• Software define the mapping between the pp g b

symbolic library and physical location • Default library: “work” Default library: work • Library “ieee” is used for many ieee packages

Page 13: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

• E g• E.g.

Li i k lib d i• Line 1: invoke a library named ieee• Line 2: makes std_logic_1164 package visible to

h b d i ithe subsequent design units• The package is normally needed for the

std_logic/std_logic_vector data type

RTL Hardware Design by P. Chu Chapter 3

13

Page 14: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

RTL Hardware Design by P

Chapter 3

14

Processing of VHDL codeDesign by P. Chu

• Analysis▫ Performed on “design unit” basis

Ch k h d l h i i ▫ Check the syntax and translate the unit into an intermediate form

▫ Store it in a libraryStore it in a library• Elaboration▫ Bind architecture body with entityy y▫ Substitute the instantiated components with

architecture description C t “fl tt d”' d i ti▫ Create a “flattened”' description

• Execution▫ Simulation or synthesis ▫ Simulation or synthesis

Page 15: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

15

2. Lexical elements and program format

RTL H dCh t 3 RTL Hardware Design by P. Chu

Chapter 3

Page 16: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

L i l lRTL Hardware Design by P

Chapter 3

16

Lexical elementsDesign by P. Chu

• Lexical element:▫ Basic syntactical units in a VHDL program

• Types of Lexical elements:▫ Comments ▫ Identifiers▫ Reserved words▫ Numbers▫ Characters▫ Strings

Page 17: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

CommentsComments• Starts with - -

J t f l it • Just for clarity • e.g.,

RTL Hardware Design by P. Chu Chapter 3

17

Page 18: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

Identifier RTL Hardware Design by P

Chapter 3

18

Identifier

• Identifier is the name of an object

Design by P. Chu

Identifier is the name of an object• Basic rules:▫ Can only contain alphabetic letters decimal digits ▫ Can only contain alphabetic letters, decimal digits

and underscore▫ The first character must be a letterThe first character must be a letter▫ The last character cannot be an underscore▫ Two successive underscores are not allowed▫ Two successive underscores are not allowed

Page 19: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

RTL Hardware Design by P

Chapter 3

19

Examples

Design by P. Chu

Examples

• Valid examples: • Valid examples: A10, next_state, NextState, mem_addr_enable

• Invalid examples:• Invalid examples:sig#3, _X10, 7segment, X10_, hi_ _thereVHDL is case insensitive:• VHDL is case insensitive:▫ Following identifiers are the same:

nextstate NextState NEXTSTATE nEXTsTATEnextstate, NextState, NEXTSTATE, nEXTsTATE

Page 20: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

Reserved wordsReserved words

RTL Hardware Design by P. Chu Chapter 3

20

Page 21: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

RTL Hardware Design by P

Chapter 3

21

Numbers, characters and stringsDesign by P. Chu

• Number:▫ Integer: 0, 1234, 98E7▫ Real: 0.0, 1.23456 or 9.87E6▫ Base 2: 2#101101#Ch t • Character: ▫ ‘A’, ‘Z’, ‘1’

• Strings• Strings▫ “Hello”, “101101”

• Note • Note ▫ 0 and ‘0’ are different▫ 2#101101# and “101101” are different

Page 22: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

Program formatProgram format

• VHDL is “free-format”: blank space, tab, new-line can be freely inserted

• e.g., the following are the same

RTL Hardware Design by P. Chu Chapter 3

22

Page 23: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

RTL Hardware Design by P

Chapter 3

23

Design by P. Chu

Page 24: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

• A good g“header”

RTL Hardware Design by P. Chu Chapter 3

24

Page 25: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

25

3 Objects3. ObjectsRTL H dCh t 3 RTL Hardware Design by P. Chu

Chapter 3

Page 26: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

RTL Hardware Design by P

Chapter 3

26

Objects

Design by P. Chu

Objects• A named item that hold a value of specific data A named item that hold a value of specific data

type• Four kinds of objectsj▫ Signal ▫ Variable▫ Constant▫ File (cannot be synthesized)

l d• Related construct▫ Alias

Page 27: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

SignalSignal

• Declared in the architecture body's declaration section

• Signal declaration:signal signal_name, signal_name, ... : data_type

• Signal assignment: signal_name <= projected_waveform;P i i d l i id d i l• Ports in entity declaration are considered as signals

• Can be interpreted as wires or “wires with memory” (i.e., FFs latches etc ) FFs, latches etc.)

RTL Hardware Design by P. Chu Chapter 3

27

Page 28: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

VariableVariable

• Declared and used inside a process• Variable declaration:

variable variable_name, ... : data_type

• Variable assignment: variable_name := value_expression;

• Contains no “timing info” (immediate assignment)U d i t diti l PL “ b li l ti ” • Used as in traditional PL: a “symbolic memory location” where a value can be stored and modified

• No direct hardware counterpart• No direct hardware counterpart

RTL Hardware Design by P. Chu Chapter 3

28

Page 29: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

ConstantConstant

• Value cannot be changed• Constant declaration:

constant const_name, ... : data_type := value_expression

• Used to enhance readability ▫ E.g.,

RTL Hardware Design by P. Chu Chapter 3

29

Page 30: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

• It is a good idea to avoid “hard literals”g

RTL Hardware Design by P. Chu Chapter 330

Page 31: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

AliasAlias

• Not a object• Alternative name for an object• Used to enhance readability ▫ E.g.,

RTL Hardware Design by P. Chu Chapter 3

31

Page 32: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

RTL Hardware Design by P

Chapter 3

32

4 Data type and operators

Design by P. Chu

4. Data type and operators

• Standard VHDL• Standard VHDL• IEEE1164_std_logic package• IEEE numeric std package• IEEE numeric_std package

Page 33: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

RTL Hardware Design by P

Chapter 3

33

Data type

Design by P. Chu

Data type

• Definition of data type• Definition of data type▫ A set of values that an object can assume.▫ A set of operations that can be performed on ▫ A set of operations that can be performed on

objects of this data type.• VHDL is a strongly-typed language• VHDL is a strongly-typed language▫ an object can only be assigned with a value of its

type type ▫ only the operations defined with the data type can

be performed on the objectbe performed on the object

Page 34: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

RTL Hardware Design by P

Chapter 3

34

Data types in standard VHDL

Design by P. Chu

Data types in standard VHDL

• integer: • integer: ▫ Minimal range: -(2^31-1) to 2^31-1▫ Two subtypes: natural positive▫ Two subtypes: natural, positive

• boolean: (false, true)bit: ('0' '1')• bit: ( 0 , 1 )▫ Not capable enough bit t di i l f bit• bit_vector: a one-dimensional array of bit

Page 35: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

RTL Hardware Design by P

Chapter 3

35

Operators in standard VHDL

Design by P. Chu

Operators in standard VHDL

Page 36: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

RTL Hardware Design by P

Chapter 3

36

Design by P. Chu

Page 37: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

RTL Hardware Design by P

Chapter 3

37

IEEE std_logic_1164 packageDesign by P. Chu

• What’s wrong with bit?• New data type: std_logic, std_logic_vectoryp g , g• std_logic: ▫ 9 values: ('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-')

'0', '1': forcing logic 0' and forcing logic 1'Z': high-impedance, as in a tri-state buffer.'L' 'H' k l i d k l i i i d l i'L' , 'H': weak logic 0 and weak logic 1, as in wired-logic'X', 'W': “unknown” and “weak unknown”'U': for uninitializedU : for uninitialized'-': don't-care.

Page 38: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

RTL Hardware Design by P

Chapter 3

38

• std_logic_vector▫ an array of elements with std logic data type

Design by P. Chu

▫ an array of elements with std_logic data type▫ Imply a bus▫ E g ▫ E.g.,

signal a: std_logic_vector(7 downto 0);▫ Another form (less desired)Another form (less desired)

signal a: std_logic_vector(0 to 7);• Need to invoke package to use the data type:• Need to invoke package to use the data type:

library ieee;use ieee std logic 1164 all;use ieee.std_logic_1164.all;

Page 39: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

Overloaded operator IEEE std_logic_1164 package

h h d d b l d• Which standard VHDL operators can be applied to std_logic and std_logic_vector?Overloading: same operator of different data types • Overloading: same operator of different data types

• Overloaded operators in std_logic_1164 package

RTL Hardware Design by P. Chu Chapter 3

39

Page 40: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

• Type conversion function in std_logic_1164 package:

RTL Hardware Design by P. Chu Chapter 3

40

Page 41: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

• E.g.,

RTL Hardware Design by P. Chu Chapter 3

41

Page 42: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

RTL Hardware Design by P

Chapter 3

42

Operators over an array data type

Design by P. Chu

Operators over an array data type

• Relational operators for array• Relational operators for array▫ operands must have the same element type but

their lengths may differtheir lengths may differ▫ Two arrays are compared element by element,

form the left most elementform the left most element▫ All following returns true

"011"="011", "011">"010", "011">"00010", 011 011 , 011 > 010 , 011 > 00010 , "0110">"011"

Page 43: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

RTL Hardware Design by P

Chapter 3

43

Design by P. Chu

• Concatenation operator (&)• Concatenation operator (&)• e.g.,

y <= "00" & a(7 downto 2);y <= 00 & a(7 downto 2);y <= a(7) & a(7) & a(7 downto 2);y <= a(1 downto 0) & a(7 downto 2);y <= a(1 downto 0) & a(7 downto 2);

Page 44: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

A tRTL Hardware Design by P

Chapter 3

44

Array aggregateA t i VHDL t t t i l t

Design by P. Chu

• Aggregate is a VHDL construct to assign a value to an array-typed object

• E gE.g.,a <= "10100000";a <= (7=>'1', 6=>'0', 0=>'0', 1=>'0', 5=>'1',

4 >'0' 3 >'0' 2 >'1')4=>'0', 3=>'0', 2=>'1');a <= (7|5=>'1', 6|4|3|2|1|0=>'0');a <= (7|5=>'1', others=>'0');(7|5 , );

• E.g., a <= "00000000"a < (others >'0')a <= (others=>'0');

Page 45: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

RTL Hardware Design by P

Chapter 3

45

IEEE numeric std package

Design by P. Chu

IEEE numeric_std package

• How to infer arithmetic operators?• How to infer arithmetic operators?• In standard VHDL:

signal a b sum: integer;signal a, b, sum: integer;. . .sum <= a + b;sum <= a + b;

• What’s wrong with integer data type?

Page 46: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

RTL Hardware Design by P

Chapter 3

46

• IEEE numeric std package: define integer as a

Design by P. Chu

IEEE numeric_std package: define integer as a an array of elements of std_logic

• Two new data types: unsigned, signedyp g , g• The array interpreted as an unsigned or signed

binary number• E.g.,

signal x, y: signed(15 downto 0);d i k k h d• Need invoke package to use the data type

library ieee;use ieee std logic 1164 all;use ieee.std_logic_1164.all;use ieee.numeric_std.all;

Page 47: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

RTL Hardware Design by P

Chapter 3

47

Overloaded operators in Design by P. Chu

IEEE numeric_std package

Page 48: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

• E.g.,

RTL Hardware Design by P. Chu Chapter 3

48

Page 49: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

RTL Hardware Design by P

Chapter 3

49

New functions in Design by P. Chu

IEEE numeric_std package

Page 50: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

RTL Hardware Design by P

Chapter 3

50

Type conversionDesign by P. Chu

• Std_logic_vector, unsigned, signed are defined as an array of element of std_logic

• They considered as three different data types in VHDL

• Type conversion between data types:▫ type conversion function▫ Type casting (for “closely related” data types)

Page 51: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

RTL Hardware Design by P

Chapter 3

51

Type conversion between number-Design by P. Chu

related data types

Page 52: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

RTL Hardware Design by P

Chapter 3

52

• E.g.

Design by P. Chu

library ieee;use ieee.std_logic_1164.all;

i i td lluse ieee.numeric_std.all;. . .signal s1 s2 s3 s4 s5 s6: std logic vector(3 downto 0);signal s1, s2, s3, s4, s5, s6: std_logic_vector(3 downto 0);signal u1, u2, u3, u4, u6, u7: unsigned(3 downto 0);signal sg: signed(3 downto 0);signal sg: signed(3 downto 0);

Page 53: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

RTL Hardware Design by P

Chapter 3

53

• E.g.library ieee;

Design by P. Chu

library ieee;use ieee.std_logic_1164.all;use ieee.numeric_std.all;;. . .signal s1, s2, s3, s4, s5, s6: std_logic_vector(3 downto 0);signal u1, u2, u3, u4, u6, u7: unsigned(3 downto 0);signal sg: signed(3 downto 0);

Page 54: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

kRTL Hardware Design by P

Chapter 3

54

▫ Oku3 <= u2 + u1; --- ok, both operands unsigned

Design by P. Chu

u4 <= u2 + 1; --- ok, operands unsigned and natural

▫ Wrongu5 <= sg; -- type mismatchu6 <= 5; -- type mismatch▫ Fixu5 <= unsigned(sg); -- type castingu6 <= to_unsigned(5,4); -- conversion function

Page 55: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

RTL Hardware Design by P

Chapter 3

55

▫ Wrongu7 <= sg + u1; -- + undefined over the types

Design by P. Chu

7 g ; yp▫ Fixu7 <= unsigned(sg) + u1; -- ok, but be careful7 g ( g) ; ,

▫ Wronggs3 <= u3; -- type mismatchs4 <= 5; -- type mismatchs4 < 5; type mismatch▫ Fixs3 <= std logic vector(u3); -- type castings3 < std_logic_vector(u3); type castings4 <= std_logic_vector(to_unsigned(5,4));

Page 56: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

RTL Hardware Design by P

Chapter 3

56

▫ Wrongs5 <= s2 + s1; + undefined over std_logic_vector

Design by P. Chu

s6 <= s2 + 1; + undefined▫ Fixs5 <= std_logic_vector(unsigned(s2) + unsigned(s1)); s6 <= std_logic_vector(unsigned(s2) + 1); g g ;

Page 57: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

Non-IEEE package RTL Hardware Design by P

Chapter 3

57

Non-IEEE package• Packagea by Synopsys

Design by P. Chu

g y y p y• std_logic_arith: ▫ Similar to numeric_std▫ New data types: unsigned, signed▫ Details are different

• std_logic_unsigned/ std_logic_signed▫ Treat std_logic_vector as unsigned and signed

b numbers ▫ i.e., overload std_logic_vector with arith

operationsoperations

Page 58: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

RTL Hardware Design by P

Chapter 3

58

• Software vendors frequently store them in ieeelibrary:

Design by P. Chu

library:• E.g.,

library ieee;library ieee;use ieee.std_logic_1164.all;use ieee.std arith unsigned.all;use ieee.std_arith_unsigned.all;. . .signal s1, s2, s3, s4, s5, s6: std logic vector(3 downto 0);g , , 3, 4, 5, _ g _ (3 );. . .s5 <= s2 + s1; -- ok, + overloaded with std_logic_vectorgs6 <= s2 + 1; -- ok, + overloaded with std_logic_vector

Page 59: Basic Language Constructs of VHDLgalia.fc.uaslp.mx/~rmariela/digital/unidad2-2.pdf · 1 Basic Language Constructs of VHDL Unit 2 Ch t 3 RTL H d 3rd Part Digital Electronics RTL Hardware

RTL Hardware Design by P

Chapter 3

59

• Only one of the std_logic_unsigned and

Design by P. Chu

y g gstd_logic_signed packages can be used

• The std logic unsigned/std logic signed_ g _ g / _ g _ gpackages beat the motivation behind a strongly-typed languageyp g g

• Numeric_std is preferred