A function statement defines a group of sequential statements that return a single value.

 

A function specification includes—in this order—the reserved word "function", the function’s name, a parameter list (which can only include constants and signal objects, and must all be of mode in), the reserved word "return", and the type of the value to be returned by the function.

 

Example

    function to_unsigned (a: std_ulogic_vector)

                 return integer is

            alias av: std_ulogic_vector (1 to a'length) is a;

            variable ret,d: integer;

    begin

            d := 1;

            ret := 0;

 

            for i in a'length downto 1 loop

                if (av(i) = '1') then

                    ret := ret + d;

                end if;

                d := d * 2;

            end loop;

 

            return ret;

    end to_unsigned;

 

LRM

    2.1

 

See also

image\diamond.gif  Return

image\diamond.gif  Pure

image\diamond.gif  Impure

image\diamond.gif  Functions and Procedures