VHDL Programming

(C. Jardin) #1

146 Chapter Six


-- returns 0
END PROCESS;

This example shows how the different attributes can be used to return
information about a type. When ranges of a type are defined using (a TO
b)where b > a, the ’LEFTattribute will always equal the ’LOWattribute;
but when a range specification using (b DOWNTO a)where b > a is used,
the ’HIGHand ’LOWcan be used to determine the upper and lower bounds
of the type.
Value type attributes are not restricted to numeric types. These attributes
can also be used with any scalar type. Following is an example using
enumerated types:

ARCHITECTURE b OF a IS
TYPE color IS (blue, cyan, green, yellow, red, magenta);
SUBTYPE reverse_color IS color RANGE red DOWNTO green;
SIGNAL color1, color2, color3,
color4, color5, color6,
color7, color8 : color;
BEGIN

color1 <= color’LEFT; -- returns blue
color2 <= color’RIGHT; -- returns magenta

color3 <= color’HIGH; -- returns magenta
color4 <= color’LOW; -- returns blue

color5 <= reverse_color’LEFT;
-- returns red

color6 <= reverse_color’RIGHT;
-- returns green

color7 <= reverse_color’HIGH;
-- returns red

color8 <= reverse_color’LOW;
-- returns green
END b;

This example illustrates how value type attributes can be used with
enumerated types to return information about the type. Signals color1
and color2are assigned blueand magenta, respectively, the left and right
bounds of the type. It is easy to see how these values are obtained by
examining the declaration of the type. The left bound of the type is blue
and the right bound is magenta. What is returned for the ’HIGHand ’LOW
attributes of an enumerated type? The answer relates to the position
numbers of the type. For an integer and real type, the position numbers
Free download pdf