Although variables represent data like the signal, they do not have or cause events and are modified differently. Variables are modified with the variable assignment. For example,
a:=b;assigns the value of b to a. The value is simply copied to a immediately. Since variables may only be used in processes, the assignment statement may only appear in a process. The assignment is performed when the process is executed, as explained in the last section.
The following example shows how a variable is used in a process.
count: process (x) variable cnt : integer := -1; begin cnt:=cnt+1; end process;Variable declarations appear before the begin keyword of a process statement as in the example. The variable declaration is the same as the signal declaration except the key word variable is used instead of signal. The declaration in this example includes an optional part, which specifies the initial value of the variable, when a simulation begins. The initialization part is included by adding the := and some constant expression after the type part of the declaration. This initialization part may also be included in signal declarations. The variable cnt is declared to be of the type integer. The integer type represents negative and positive integer values.
The process in the example contains one statement, the assignment statement. This assignment computes the value of cnt plus one and immediately stores that new value in the variable cnt. Thus, cnt will be incremented by one each time this process is executed. Remember, from the last section, that a process is executed once at the beginning of simulation and then each time an event occurs on any signal in its sensitivity list. Since the value is initialized to -1, and the process is executed once before beginning simulation, the value of cnt will be 0 when simulation begins. Once simulation begins, cnt will be incremented by one each time the signal x changes, since x is in the sensitivity list. If x is a bit signal, then this process will count the number of rising and falling edges that occur on the signal x.
The previous section is Behavioral Descriptions - The
The next section is Behavioral Descriptions - Sequential Statements.