VHDL Programming

(C. Jardin) #1

Predefined Attributes 147


of a value are equal to the value itself; but for an enumerated type, the
position numbers of a value are determined by the declaration of the type.
Values declared earlier have lower position numbers than values declared
later. Value bluefrom the preceding example has a position number of 0,
because it is the first value of the type. Value cyanhas a position number
1,greenhas 2, and so on. From these position numbers, the high and low
bounds of the type can be found.
Signals color5through color8are assigned attributes of the type
reverse_color. This type has a DOWNTOrange specification. Attributes
’HIGHand ’RIGHTdo not return the same value because the range is
reversed. Value redhas a higher position number than value green, and
therefore a DOWNTOis needed for the range specification.

Value Array Attributes


There is only one value array attribute:’LENGTH. Given an array type, this
attribute returns the total length of the array range specified. This
attribute works with array ranges of any scalar type and with multi-
dimensional arrays of scalar-type ranges. Following is a simple example:

PROCESS(a)
TYPE bit4 IS ARRAY(0 TO 3) of BIT;
TYPE bit_strange IS ARRAY(10 TO 20) OF BIT;
VARIABLE len1, len2 : INTEGER;
BEGIN
len1 := bit4’LENGTH; -- returns 4
len2 := bit_strange’LENGTH; -- returns 11
END PROCESS;

The assignment to len1assigns the value of the number of elements
in array type bit4. The assignment to len2assigns the value of the num-
ber of elements of type bit_strange.
This attribute also works with enumerated-type ranges, as shown by
the following example:

PACKAGE p_4val IS
TYPE t_4val IS (’x’, ’ 0 ’, ’ 1 ’, ’z’);
TYPE t_4valX1 IS ARRAY(t_4val’LOW TO t_4val’HIGH) OF
t_4val;

TYPE t_4valX2 IS ARRAY(t_4val’LOW TO t_4val’HIGH) OF
t_4valX1;

TYPE t_4valmd IS ARRAY(t_4val’LOW TO t_4val’HIGH,
t_4val’LOW TO t_4val’HIGH) OF t_4val;
Free download pdf