Subprograms and Packages 133
Procedures
In the earlier section describing functions, we discussed how functions can
have a number of input parameters and always return one value. In con-
trast, procedures can have any number of in, out, and inout parameters. A
procedure call is considered a statement of its own; a function usually ex-
ists as part of an expression. The most usual case of using a procedure is
when more than one value is returned.
Procedures have basically the same syntax and rules as functions. A
procedure declaration begins with the keyword PROCEDURE, followed by
the procedure name, and then an argument list. The main difference be-
tween a function and a procedure is that the procedure argument list
most likely has a direction associated with each parameter; the function
argument list does not. In a procedure, some of the arguments can be mode
IN,OUT, or INOUT; in a function, all arguments are of mode INby default
and can only be of mode IN.
A typical example where a procedure is very useful is during the con-
version from an array of a multivalued type to an integer. A procedure
showing an example of how to accomplish this is shown here:
USE LIBRARY IEEE;
USE IEEE.std_logic_1164.ALL;
PROCEDURE vector_to_int (z : IN std_logic_vector;
x_flag : OUT BOOLEAN; q : INOUT INTEGER) IS
BEGIN
q := 0;
x_flag := false;
FOR i IN z’RANGE LOOP
q := q * 2;
IF z(i) = ‘ 1 ’ THEN
q := q + 1;
ELSIF z(i) /= F0 THEN
x_flag := TRUE;
END IF;
END LOOP;
END vector_to_int;
The behavior of this procedure is to convert the input argument zfrom
an array of a type to an integer. However, if the input array has unknown
values contained in it, an integer value cannot be generated from the ar-
ray. When this condition occurs, output argument x_flagis set to true,
indicating that the output integer value is unknown. A procedure was
required to implement this behavior because more than one output value