Functions
Produce a single return value
Cannot modify the parameters passed to them
Require a RETURN statement
FUNCTION add_bits2 (a, b : IN BIT) RETURN BIT IS
VARIABLE result : BIT; -- variable is local to function
RETURN result; -- the two functions are equivalent
FUNCTION add_bits (a, b : IN BIT) RETURN BIT IS
BEGIN -- functions cannot return multiple values
Notes:
Functions must have a return value and a return statement and cannot modify the parameters passed to them. They are called in statements where a value is needed (e.g. assignment statements, conditional tests). Note that only one value can be returned by a function call.
A function can have multiple return statements; the simulator will exit the function when it encounters the first return statement in the execution of the function.