VHDL Programming

(C. Jardin) #1

Sequential Processing 51


LOOP_parameter_specification ::=
identifier IN discrete_range

The LOOP statement has an optional label, which can be used to
identify the LOOP statement. The LOOP statement has an optional
iteration_schemethat determines which kind of LOOPstatement is being
used. The iteration_schemeincludes two types of LOOPstatements: a
WHILE condition LOOP statement and a “FOR identifier IN
discrete_range”statement. The FORloop loops as many times as specified
in the discrete_range, unless the loop is exited. The WHILE condition
LOOPstatement loops as long as the condition expression is TRUE.
Let’s look at a couple of examples to see how these statements work:

WHILE (day = weekday) LOOP
day := get_next_day(day);
END LOOP;

This example uses the WHILE conditionform of the LOOPstatement.
The condition is checked each time before the loop is executed. If the condi-
tion is TRUE,the LOOPstatements are executed. Control is then transferred
back to the beginning of the loop. The condition is checked again. If TRUE,
the loop is executed again; if not, statement execution continues on the
statement following the END LOOPclause.
The other version of the LOOPstatement is the FORloop:

FOR i IN 1 to 10 LOOP
i_squared(i) := i * i;
END LOOP;

This loop executes 10 times whenever execution begins. Its function is
to calculate the squares from 1 to 10 and insert them into the i_squared
signal array. The index variable istarts at the leftmost value of the range
and is incremented until the rightmost value of the range.
In some languages, the loop index (in this example,i) can be assigned
a value inside the loop to change its value. VHDL does not allow any
assignment to the loop index. This also precludes the loop index existing
as the return value of a function, or as an out or inout parameter of a
procedure.
Another interesting point about FOR LOOPstatements is that the index
value iis locally declared by the FORstatement. The variable idoes not
need to be declared explicitly in the process, function, or procedure. By
virtue of the FOR LOOPstatement, the loop index is declared locally. If
Free download pdf