Sequential Processing 47
IF Statements
In Appendix A of the VHDL Language Reference Manual, all VHDL con-
structs are described using a variant of the Bachus-Naur format(BNF)
that is used to describe typical programming languages. If you are not
familiar with BNF, Appendix C gives a cursory description. Becoming
familiar with the BNF will help you better understand how to construct
complex VHDL statements.
The BNF description of the IFstatement looks like this:
if_statement ::=
IF condition THEN
sequence_of_statements
{ELSIF condition THEN
sequence_of_statements}
[ELSE
sequence_of_statements]
END IF;
From the BNF description, we can conclude that the IFstatement
starts with the keyword IFand ends with the keywords END IFspelled
out as two separate words. There are also two optional clauses: the ELSIF
clause and the ELSEclause. The ELSIFclause is repeatable—more than
one ELSIFclause is allowed; but the ELSEclause is optional, and only
one is allowed. The condition construct in all cases is a boolean expres-
sion.This is an expression that evaluates to either true or false. When-
ever a condition evaluates to a true value, the sequence of statements
following is executed. If no condition is true, then the sequence of state-
ments for the ELSEclause is executed, if one exists. Let’s analyze a few
examples to get a better understanding of how the BNF relates to the
VHDL code.
The first example shows how to write a simple IFstatement:
IF (x < 10) THEN
a := b;
END IF;
The IFstatement starts with the keyword IF. Next is the condition
(x < 10), followed by the keyword THEN. The condition is true when the
value of xis less than 10; otherwise it is false. When the condition is true,
the statements between the THENand END IFare executed. In this exam-
ple, the assignment statement (a := b) is executed whenever xis less than
- What happens if xis greater than or equal to 10? In this example, there