The variable keyword declares a variable of a specified type.

 

A variable declaration includes—in this order—the reserved word "variable", the variable’s name, the variable’s subtype, and, optionally, an expression specifying the initial value of the variable.

 

A variable can only be declared within a process, procedure or function.  Also, a variable cannot be of a file type. Variables declared within a process have their values preserved during subsequent executions of the process. Variables declared within a function or procedure have their values initialized each time the function or procedure is called.

 

Example

    process(Rst,Clk)

            variable Q: integer range 0 to 15;

    begin

        if Rst = '1' then                -- Asynchronous reset

            Q := 0;

        elsif rising_edge(Clk) then

            if Load = '1' then

                Q := to_unsigned(Data);    -- Convert vector to

              -- integer

            elsif Q = 15 then

                Q := 0;

            else

                Q := Q + 1;

            end if;

        end if;

        Count <= to_vector(4,Q);  -- Convert integer to

            -- vector

    end process;

 

LRM

    4.3

 

See also

image\diamond.gif  Signal

image\diamond.gif  Sequential Statements

image\diamond.gif  Objects, Data Types and Operators