Chapter 2 VHDL Basics Lexical elements Object declaration
Chapter 2 VHDL Basics ä Lexical elements, ä Object declaration separators and delimiters ä Identifiers ä Reserved words ä Literal ä Package and type ä Entity and 10/31/2021 EE 514 architecture ä Predefined attributes ä Names and operators 1
Lexical element , separators and delimiters ä Lexical elements: delimiter, identifier, reserved word, abstract literal, character literal, string literal, bit string literal, comment ä Separator Adjacent lexical elements are separated by separator such as a space characters, format effectors or the end of a line. 10/31/2021 EE 514 2
Lexical element , separators and delimiters ä Delimiter & ‘ ( ) * + , -. / : ; < = > | ä Compound delimiter => ** : = /= >= <= <> ä Comment starts with two adjacent hyphens and extends to the end of the line. 10/31/2021 EE 514 3
Identifiers ä ä Identifiers are used as user names and as reserved words. Each identifier starts with a letter followed by any number of letters or digits. A single underline character can be inserted between a letter or digit and an adjacent letter or digit. An underline character as the last character is not a valid identifier. Two adjacent underline characters are not allowed in identifiers. There is no distinction between an uppercase letter and a lowercase letter within an identifier. Space characters are not allowed within an identifier since they are separators. 10/31/2021 EE 514 4
Identifiers ä Examples Valid identifiers: carry_OUT Dim_Sun Count 7 SUB_2_go. X 10/31/2021 Invalid identifiers: 7 AB (starts with a digit) A@B (special character@) SUM_ (end with an underline) PI__A (two underline characters) EE 514 5
Reserved words Abs and begin case downto exit generic is map nor open port severity transport variable 10/31/2021 access architecture block component else file guarded label mod not or procedure signal type wait after array body configuration elsif for if library nand null others process subtype units when EE 514 alias assert buffer constant end function in linkage new of out range then until while all attribute bus disconnect entity generate inout loop next on package record to use with xor 6
Literal 10/31/2021 EE 514 7
Literals A decimal or based literal can be an integer, a real, or a real with an exponent. Integer literals: 21, 0, IE 2, 3 e 4, 123000. Real literals: 11. 0, 0. 468, 3. 14_592_6. Real literals with exponent: 1. 23 E-11, 1. 0 E+4, 3. 024 E+23. The exponent letter E, can be written either in lower- or uppercase with the same meaning. The underline character inserted between adjacent digits of a decimal literal does not affect the value of the literal. An exponent for an integer literal must not have a minus sign -. 2 E-3 is not an integer. Based literals: 2#1111_1100#, 16#fc#, 7#510# all equal to 252 base 2#0110_0000#, 16#6#E 1 both equal to 96 number exponent (in the same base 16) 10/31/2021 EE 514 8
Literals • A character literal is formed by any graphic character between two apostrophe characters. Examples: ‘A’, ’a’, ’%’, ’’’, ’ ‘ • A string literal is a sequence of graphic characters between two quotation characters. Examples: "Setup time violation ” , ""empty), " ” (space), "A” , """” (quotation). It must fit in the same line. Concatenation (&) can be used to form a longer string literal. • Bit string literals are formed by sequences of extended digits such as 0 through 9, A through F, or a through f enclosed between two quotations, preceded by a base specifier of B, 0, or X for binary, octal, or hexadecimal. The length of a bit string literal is the number of BIT values in the sequence. For example: X"F_FF”, 0"7777", b"1111_1111” all represent the same value of 12 bits. 10/31/2021 EE 514 9
Package LITERAL ä ä ä package LITERAL is type intary is array(0 to 5) of integer; type realary is array(0 to 5) of real; type bitary is array(0 to 5) of bit_vector; constant INT : intary : = (12_000, 1 E_0, 2#1101#, 5#44#, 16#F# E 3, 3#3#); constant R 1 : realary : = (1_0. 00, 100_. 0, 1. 1 E-2, 2#10. 11#, 16#F#E 2, 1_0. 0); constant b 1 : bitary : = (2"110", B"1101", O"047", H"ABcd", 10"99", "0101"); constant b 2 : bit_vector : = 10"99"; end LITERAL; 10/31/2021 EE 514 10
Package Standard package STANDARD is type BOOLEAN is (FALSE, TRUE); type BIT is ('0', '1'); type CHARACTER is ( NUL, SOH, STX, EOT, ENQ, ACK, BEL, BS, HT, LF, VT, FF, CR, SO, SI, DLE, DC 1, DC 2, DC 3, DC 4, NAK, SYN, ETB, CAN, EM, SUB, ESC, FSP, GSP, RSP, USP, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ', ', '-', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ': ', '; ', '<', '=', '>', '? ', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 10/31/2021 'x', 'y', 'z', '{', '|', '}', '~', DEL); type SEVERITY_LEVEL is (NOTE, WARNING, ERROR, FAILURE); type INTEGER is range -214748 to +214748; type REAL is range -0. 1797693134862 e+309 to + 0. 1797693134862 e+309 type TIME is range -9223372036854775807 to + 9223372036854775807 units fs; -- femtosecond ps = 1000 fs; -- picosecond ns = 1000 ps; -- nanosecond us = 1000 ns; -- microsecond ms = 1000 us; -- millisecond sec = 1000 ms; -- second min = 60 sec; -- minute hr = 60 min; -- hour end units; function NOW return TIME; subtype NATURAL is INTEGER range 0 to INTEGER'HIGH; subtype POSITIVE is INTEGER range 1 to INTEGER'HIGH; type STRING is array ( POSITIVE range <> ) of CHARACTER; type BIT_VECTOR is array ( NATURAL range <> ) of BIT; end STANDARD; EE 514 11
Package and type package TYPES is type LOGIC 4 is ('X', '0', '1', 'Z'); type STATE is (IDLE, ADDR, DATA); type LIGHT is (GREEN, YELLOW, RED); type ADDRESS is range 0 to 16#FFFF#; subtype BIT_INDEX is integer range 0 to 7; subtype BYTE is BIT_VECTOR(BIT_INDEX); type A_BYTE is array (7 downto 0) of bit; type B_BYTE is array (7 downto 0) of bit; type TWO_DIMENSION is array (NATURAL range <>, NATURAL range <>) of bit; type RISC is record OPCODE : A_BYTE; ADDR 1 : ADDRESS; end record; type CELL; type POINTER is access CELL; type CELL is record ID : INTEGER; PTR : POINTER; end record; end TYPES; 10/31/2021 Defined. EE 514 in Standard Package 12
Object declaration Object_declaration: : = constant identifier_list: subtype_indication[: =expression]; variable identifier_list: subtype_indication[: =expression]; signal identifier_list: subtype_indication[signal_kind] [: =expression]; signal_kind: : =register | bus identifier_list: : =identifier {, identifier} 10/31/2021 EE 514 13
Entity and architecture RTL 3 of NANDXOR is entity NANDXOR is signal T : bit; port ( A, B : in bit; begin C : in bit; T <= A nand B; D : out bit); p 1 : process (T, C) end NANDXOR; begin architecture RTL 1 of NANDXOR is D <= T xor C; begin end process p 1; D <= (A nand B) xor C; end RTL 3; end RTL 1; architecture RTL 2 of NANDXOR is begin process (A, B, C) begin if (C = '0') then D <= A nand B; else D <= A and B; end if; end process; 10/31/2021 end RTL 2; EE 514 14
Predefined attributes TS'left, TS’right, TS'low TS'high They return the left bound, light bound, low bound, and high bound, respectively. For example, type A_BYTE is array (7 downto 0) of bit; , A_BYTE'left =A_BYTE'high = 7, A_BYTE'low = A_BYTE'right =0. TS'base Returns the base type of TS. It should be used with another attribute such as TS'base'low. TS'POS(X) Returns the position within the discrete or physical type of the value of the parameter X. TS'val(X) Returns the value at the position within the discrete or physical type of the value of the parameter X. TS'succ(X), TS'pred(X) They return the value at the position within the discrete or physical type whose position is one greater and one less of the value of the parameter X, respectively. 10/31/2021 EE 514 15
Predefined attributes TS'leftof(X), TS'rightof(X) Return the value at the position within the discrete or physical type whose position is to the left and to the right of the value of the parameter X, respectively. Array atributes: A'Ieft(N), A'right(N), A'high(N), A'low(N), A'length(N) Return the left bound, right bound, lower bound, right bound, the number of values of the Nth index of the array object or subtypes, respectively (default N=1). For example, signal RAM: 'TWO-DIMENSION (0 to 10, 0 to 15); RAM'Left(2)= RAM'Low(2) = RAM'Low(l) = RAM'Left=RAM'Left(l) = 0 A'range(N), A'reverse-range(N) Return the range and the reverse range of the Nth index of the array object or subtypes respectively. For example, RAM'range(2) is 0 to 15, RAM'reverse-range is 10 downto 0. These ranges can be used in a loop statement. 10/31/2021 EE 514 16
Names and operators Simple names are identifiers such as COUNTER, CLK. Indexed names are used to denote array element such as RAM(1, 3) and INSTRUCTION(5). Slice names are portions of objects such as INSTRUCTION(7 downto 0). Selected names select objects of a record, or a library as WORK. DESIGN selects design entity DESIGN from the library WORK Attribute names denote attributes like CLK’stable(3 ns) 10/31/2021 EE 514 17
Operators From lowest to highest order of precedence ä ä ä Logical and or Relational = /= Adding and Concatenation Sign (unary) + Multiplying * / mod Other ** abs 10/31/2021 EE 514 nand < + nor <= - xor > & >= rem not 18
- Slides: 18