VHDL Programming

(C. Jardin) #1

50 Chapter Three


OTHERSclause is executed. It is an error if an OTHERSclause does not ex-
ist,and the choices given do not cover every possible value of the expression
type.
In the next example, a more complex type is returned by the expression.
(Types are discussed in Chapter 4,“Data Types.”) The CASEstatement
uses this type to select among the choices of the statement:

TYPE vectype IS ARRAY(0 TO 1) OF BIT;
VARIABLE bit_vec : vectype;

CASE bit_vec IS
WHEN “ 00 ” =>
RETURN 0;
WHEN “ 01 ” =>
RETURN 1;
WHEN “ 10 ” =>
RETURN 2;
WHEN “ 11 ” =>
RETURN 3;
END CASE;

This example shows one way to convert an array of bits into an integer.
When both bits of variable bit_veccontain ‘ 0 ’values, the first choice
“ 00 ”matches and the value 0 is returned. When both bits are ‘ 1 ’values,
the value 3 , or “ 11 ”, is returned. This CASEstatement does not need an
OTHERSclause because all possible values of variable bit_vecare enu-
merated by the choices.

LOOP Statements


The LOOPstatement is used whenever an operation needs to be repeated.
LOOPstatements are used when powerful iteration capability is needed to
implement a model. Following is the BNF for the LOOPstatement:

loop_statement ::=
[LOOP_label : ] [iteration_scheme] LOOP
sequence_of_statements
END LOOP[LOOP_label];

iteration_scheme ::=
WHILE condition | FOR LOOP_parameter_specification
Free download pdf