VHDL Programming

(C. Jardin) #1

Predefined Attributes 145


The left bound of a type or subtype is the leftmost entry of the range
constraint. The right bound is the rightmost entry of the type or subtype.
In the following example, the left bound is -32,767, and the right bound
is 32,767:

TYPE smallint IS -32767 TO 32767;

The upper bound of a type or subtype is the bound with the largest
value, and the lower bound is the bound with the lowest value. In the pre-
ceding example, for the type smallint, the upper bound is 32,767, and the
lower bound is -32,767.
To use one of these value attributes, the type mark name is followed
by the attribute desired. For example, following is the syntax to return the
left bound of a type:

PROCESS(x)
SUBTYPE smallreal IS REAL RANGE -1.0E6 TO 1.0E6;
VARIABLE q : real;
BEGIN
q := smallreal’LEFT;
-- use of ’left returns
-- -1.0E6
END test;

In this example, variable qis assigned the left bound of type smallreal.
Variable qmust have the same type as the bounds of the type for the
assignment to occur. (The assignment could also occur if variable qwas cast
into the appropriate type.) After the assignment has occurred, variable q
contains -1.0E6, which is the left bound of type smallreal.
In the next example, all of the attributes are used to show what happens
when a DOWNTOrange is used for a type:

PROCESS(a)
TYPE bit_range IS ARRAY(31 DOWNTO 0) OF BIT;
VARIABLE left_range, right_range, uprange, lowrange :
integer;
BEGIN
left_range := bit_range’LEFT;
-- returns 31

right_range := bit_range’RIGHT;
-- returns 0

uprange := bit_range’HIGH;
-- returns 31

lowrange := bit_range’LOW;
Free download pdf