VHDL Programming

(C. Jardin) #1

170 Chapter Six


type of type coloris type color. The statement color’LEFTreturns the
value red. In the last assignment,color_gun’BASEreturns type color,
and color’SUCC(green)returns yellow.

Range Kind Attributes


The last two predefined attributes in VHDL return a value kind of range.
These attributes work only with constrained array types and return the
index range specified by the optional input parameter. Following are the
attribute notations:

a’RANGE[(n)]

a’REVERSE_RANGE[(n)]

Attributes ’RANGEreturn the nth range denoted by the value of para-
meter n. Attribute ’RANGEreturns the range in the order specified, and
’REVERSE_RANGEreturns the range in reverse order.
Attributes ’RANGEand ’REVERSE_RANGEcan be used to control the
number of times that a loop statement loops. Following is an example:

FUNCTION vector_to_int(vect: std_logic_vector) RETURN
INTEGER IS
VARIABLE result : INTEGER := 0;
BEGIN
FOR i IN vect’RANGE LOOP

result := result * 2;

IF vect(i) = ’ 1 ’ THEN
result := result + 1;
END IF;

END LOOP;

RETURN result;
END vector_to_int;

This function converts an array of bits into an integer value. The num-
ber of times that the loop needs to be executed is determined by the
number of bits in the input argument vect. When the function call is made,
the input argument cannot be an unconstrained value; therefore, the
attribute ’RANGEcan be used to determine the range of the input vector.
The range can then be used in the loop statement to determine the number
of times to execute the loop and finish the conversion.
Free download pdf