VHDL Programming

(C. Jardin) #1

82 Chapter Four


A typical enumerated type for a four-state simulation value system looks
like this:

TYPE fourval IS ( ‘X’, ‘ 0 ’, ‘ 1 ’, ‘Z’ );

This type contains four character literal values that each represent
a unique state in the four-state value system. The values represent the
following conditions:

‘X’—An unknown value

‘ 0 ’—A logical 0 or false value

‘ 1 ’—A logical 1 or true value

‘Z’—A tristate or open collector value

Character literals are needed for values ‘ 1 ’and ‘ 0 ’to separate these
values from the integer values 1 and 0. It would be an error to use the val-
ues 1 and 0 in an enumerated type, because these are integer values. The
characters Xand Zdo not need quotes around them because they do not
represent any other type, but the quotes were used for uniformity.
Another example of an enumerated type is shown here:

TYPE color IS ( red, yellow, blue, green, orange );

In this example, the type values are very abstract—that is, not repre-
senting physical values that a signal might attain. The type values in type
colorare also all identifiers. Each identifier represents a unique value of
the type; therefore, all identifiers of the type must be unique.
Each identifier in the type has a specific position in the type, determined
by the order in which the identifier appears in the type. The first identifier
has a position number of 0, the next a position number of 1, and so on.
(Chapter 5,“Subprograms and Packages”includes some examples using
position numbers of a type.)
A typical use for an enumerated type would be representing all of the
instructions for a microprocessor as an enumerated type. For instance, an
enumerated type for a very simple microprocessor could look like this:

TYPE instruction IS ( add, sub, lda, ldb, sta, stb, outa,
xfr );

The model that uses this type might look like this:

PACKAGE instr IS
TYPE instruction IS ( add, sub, lda, ldb, sta, stb,
outa, xfr );
Free download pdf