4. Lexical Elements of VHDL
- Identifiers
Identifiers are user-defined words used to name objects in VHDL models. We have seen examples of identifiers for input and output signals as well as the name of a design entity and architecture body. When choosing an identifier one needs to follow these basic rules:
- May contain only alpha-numeric characters (A to Z, a to z, 0-9) and the underscore (_) character
- The first character must be a letter and the last one cannot be an underscore.
- An identifier cannot include two consecutive underscores.
- An identifier is case insensitive (ex. And2 and AND2 or and2 refer to the same object)
- An identifier can be of any length.
Examples of valid identifiers are: X10, x_10, My_gate1.
Some invalid identifiers are: _X10, my_gate@input, gate-input.
The above identifiers are called basic identifiers. The rules for these basic identifiers are often too restrictive to indicate signals. For example, if one wants to indicate an active low signal such as an active low RESET, one cannot call it /RESET. In order to overcome these limitations, there are a set of extended identifier rules which allow identifiers with any sequence of characters.
- An extended identifier is enclosed by the backslash, “\”, character.
- An extended identifier is case sensitive.
- An extended identifier is different from reserved words (keywords) or any basic identifier (e.g. the identifier \identity\ is allowed)
- Inside the two backslashes one can use any character in any order, except that a backslash as part of an extended identifier must be indicated by an additional backslash. As an example, to use the identifier BUS:\data, one writes: \BUS:\data\
- Extended identifiers are allowed in the VHDL-93 version but not in VHDL-87
Some examples of legal identifiers are:
Input, \Input\, \input#1\, \Rst\\as\
- Keywords (Reserved words)
Certain identifiers are used by the system as keywords for special use such as specific constructs. These keywords cannot be used as identifiers for signals or objects we define. We have seen several of these reserved words already such as in, out, or, and, port, map, end, etc. Keywords are often printed in boldface, as is done in this tutorial. For a list of all the keywords click on complete keyword list. Extended identifiers can make use of keywords since these are considered different words (e.g. the extended identifier \end\ is allowed.
- Numbers
The default number representation is the decimal system. VHDL allows integer literals and real literals. Integer literals consist of whole numbers without a decimal point, while real literals always include a decimal point. Exponential notation is allowed using the letter “E” or “e”. For integer literals the exponent must always be positive. Examples are:
Integer literals: 12 10 256E3 12e+6
Real literals: 1.2 256.24 3.14E-2
The number –12 is a combination of a negation operator and an integer literal.
To express a number in a base different from the base “10”, one uses the following convention: base#number#. A few examples follow.
Base 2: 2#10010# (representing the decimal number “18”)
Base 16: 16#12#
Base 8: 8#22#
Base 2: 2#11101# (representing the decimal number “29”)
Base 16: 16#1D#
Base 8: 8#35#
To make the readability of large numbers easier, one can insert underscores in the numbers as long as the underscore is not used at the beginning or the end.
2#1001_1101_1100_0010#
215_123
- Characters, Strings and Bit Strings
To use a character literal in a VHDL code, one puts it in a single quotation mark, as shown in the examples below:
‘a’, ‘B’, ‘,’
On the other hand, a string of characters are placed in double quotation marks as shown in the following examples:
“This is a string”,
“To use a double quotation mark inside a string, use two double quotation marks”
“This is a “”String””.”
Any printing character can be included inside a string.
A bit-string represents a sequence of bit values. In order to indicate that this is a bit string, one places the ‘B’ in front of the string: B”1001”. One can also use strings in the hexagonal or octal base by using the X or O specifiers, respectively. Some examples are:
Binary: B”1100_1001”, b”1001011”
Hexagonal: X”C9”, X”4b”
Octal: O”311”, o”113”
Notice that in the hexadecimal system, each digit represents exactly 4 bits. As a result, the number b”1001011” is not the same as X”4b” since the former has only 7 bits while the latter represents a sequence 8 bits. For the same reason, O”113” (represents 9 bits) is not the same sequence as X”4b” (represents 8 bits).