VHDL Programming

(C. Jardin) #1

48 Chapter Three


is no ELSEclause, so no statements are executed in the IFstatement. In-
stead, control is transferred to the statement after the END IF.
Let’s look at another example where the ELSEclause is useful:

IF (day = sunday) THEN
weekend := TRUE;
ELSIF (day = saturday) THEN
weekend := TRUE;
ELSE
weekday := TRUE;
END IF;

In this example, there are two variables—weekendand weekday—that
are set depending on the value of a signal called day. Variable weekendis
set to TRUEwhenever dayis equal to saturdayor sunday. Otherwise, vari-
able weekdayis set to TRUE. The execution of the IFstatement starts by
checking to see if variable dayis equal to sunday. If this is true, then the
next statement is executed and control is transferred to the statement
following END IF. Otherwise, control is transferred to the ELSIFstatement
part, and dayis checked for saturday. If variable dayis equal to saturday,
then the next statement is executed and control is again transferred to the
statement following the END IFstatement. Finally, if dayis not equal to
sundayor saturday, then the ELSEstatement part is executed.
The IFstatement can have multiple ELSIFstatement parts, but only
one ELSEstatement part. More than one sequential statement can exist
between each statement part.

CASE Statements


The CASEstatement is used whenever a single expression value can be
used to select between a number of actions. Following is the BNF for the
CASEstatement:

case_statement ::=
CASE expression IS
case_statement_alternative
{case_statement_alternative}
END CASE;

case_statement_alternative ::=
WHEN choices =>
Free download pdf