Language Elements of VHDL


Language Elements of VHDL

VHDL is generally case insensitive which means that lower case and upper case letters are not distinguished. This can be exploited to define own rules for formatting the VHDL source code. VHDL keyword could for example be written in lower case letters and self defined identifiers in upper case letters.

Statements are terminated in VHDL with a semicolon. That means as many line breaks or other constructs as wanted can be inserted or left out. Only the semicolons are considered by the VHDL compiler.

  • List are normally separated by commas.

  • Signal assignments are notated with the composite assignment operator '<='.

Lexical Elements and Syntax

When we are writing a hardware model in VHDL, it is important to annotate the code with comments. A VHDL model consists of a number of lines of text. A comment can be added to a line by writing two dashes together, followed by the comment text.

For example:

-- Company: Verilog Course Team

-- Engineer: Senthil

-- Create Date: 17:40:19 01/05/2010

-- Design Name: full Adder.vhd

-- Module Name: fulladder

-- Project Name: Adder Design

library IEEE;

use IEEE.STD_LOGIC_1164.ALL;

use IEEE.STD_LOGIC_ARITH.ALL;

use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity fulladder is

Port ( a : in STD_LOGIC;--Port Declaration

b : in STD_LOGIC;

c : in STD_LOGIC;

sum : out STD_LOGIC;

carry : out STD_LOGIC);

end fulladder;

--Architecture Starts Here

architecture Gate of fulladder is

signal a1,a2,a3: STD_LOGIC;

begin

a1 <=a xor b;

sum <=a1 xor c;

a2 <=a1 and c;

a3 <=a and b;

carry<=a2 and a3;

end Gate;

The comment extends from the two dashes to the end of the line and may include any text we wish, since it is not formally part of the VHDL model. The code of a model can include blank lines and lines that only contain comments, starting with two(--) dashes.

Identifiers


Identifiers are used to name items in a VHDL model. An identifier may only contain alphabetic letters (‘A’ to ‘Z’ and ‘a’ to ‘z’), decimal digits (‘0’to ‘9’) and the underline character (‘_’);


• must start with an alphabetic letter;

• may not end with an underline character; and

• may not include two successive underline characters.

Case of letters is not significant. Some examples of valid basic identifiers are

A X0 counter Next_Value generate_read_cycle


Some examples of invalid basic identifiers are,

last@value –– contains an illegal character for an identifier

5bit_counter –– starts with a nonalphabetic character

_A0 –– starts with an underline

A0_ –– ends with an underline

clock__pulse –– two successive underlines

Reserved Words

Some identifiers, called reserved words or keywords, are reserved for special use in VHDL, so we cannot use them as identifiers for items we define. The full list of reserved words is shown in below table,


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).