180 likes | 205 Views
Lexical elements, separators and delimiters Identifiers Reserved words Literal Package and type. Object declaration Entity and architecture Predefined attributes Names and operators. Chapter 2 VHDL Basics. Lexical element , separators and delimiters. Lexical elements :
E N D
Lexical elements, separators and delimiters Identifiers Reserved words Literal Package and type Object declaration Entity and architecture Predefined attributes Names and operators Chapter 2 VHDL Basics EE514
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. EE514
Lexical element , separators and delimiters • Delimiter & ‘ ( ) * + , - . / : ; < = > | • Compound delimiter => ** := /= >= <= <> • Comment starts with two adjacent hyphens and extends to the end of the line. EE514
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. EE514
Identifiers • Examples Valid identifiers: carry_OUT Dim_Sun Count7SUB_2_goX Invalid identifiers: 7AB (starts with a digit) A@B (special character@) SUM_ (end with an underline) PI__A (two underline characters) EE514
Reserved words Abs access after alias all and architecture array assert attribute begin block body buffer bus case component configuration constant disconnect downto else elsif end entity exit file for function generate generic guarded if in inout is label library linkage loop map mod nand new next nor not null of on open or others out package port procedure process range record severity signal subtype then to transport type units until use variable wait when while with xor EE514
Literal EE514
Literals A decimal or based literal can be an integer, a real, or a real with an exponent. Integer literals: 21, 0, IE2, 3e4, 123000. Real literals: 11.0, 0.0,0.468, 3.14_592_6 . Real literals with exponent: 1.23E-11, 1.0E+4, 3.024E+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 -. 2E-3 is not an integer. Based literals: 2#1111_1100#, 16#fc#, 7#510# all equal to 252 base 2#0110_0000#, 16#6#E1 both equal to 96 number exponent (in the same base 16) EE514
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_1111” all represent the same value of 12 bits. EE514
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, 1E_0, 2#1101#, 5#44#, 16#F# E3, 3#3#); • constant R1 : realary := • (1_0.00, 100_.0, 1.1E-2, 2#10.11#, 16#F#E2, 1_0.0); • constant b1 : bitary := • (2"110", B"1101", O"047", H"ABcd", 10"99", "0101"); • constant b2 : bit_vector := 10"99"; • end LITERAL; EE514
Package Standard package STANDARD is type BOOLEAN is (FALSE, TRUE); type BIT is ('0', '1'); type CHARACTER is ( NUL, SOH, STX, ETX, EOT, ENQ, ACK, BEL, BS, HT, LF, VT, FF, CR, SO, SI, DLE, DC1, DC2, DC3, DC4, 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', 'x', 'y', 'z', '{', '|', '}', '~', DEL); type SEVERITY_LEVEL is (NOTE, WARNING, ERROR, FAILURE); type INTEGER is range -214748 to +214748; type REAL is range -0.1797693134862e+309 to + 0.1797693134862e+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; EE514
Package and type package TYPES is type LOGIC4 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; ADDR1 : ADDRESS; end record; type CELL; type POINTER is access CELL; type CELL is record ID : INTEGER; PTR : POINTER; end record; end TYPES; EE514 Defined in Standard Package
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} EE514
Entity and architecture architecture RTL3 of NANDXOR is signal T : bit; begin T <= A nand B; p1 : process (T, C) begin D <= T xor C; end process p1; end RTL3; entity NANDXOR is port ( A, B : in bit; C : in bit; D : out bit); end NANDXOR; architecture RTL1 of NANDXOR is begin D <= (A nand B) xor C; end RTL1; architecture RTL2 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; end RTL2; EE514
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 orphysical 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. EE514
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 = 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. EE514
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) EE514
Operators From lowest to highest order of precedence • Logical and or nand nor xor • Relational = /= < <= > >= • Adding and Concatenation + - & • Sign (unary) + - • Multiplying * / mod rem • Other ** abs not EE514