Subprograms and Packages 135
END bus_average;
END intpack;
A process calling the procedure might look as shown below:
PROCESS( mem_update )
VARIABLE bus_statistics : bus_stat_t;
BEGIN
bus_statistics.bus_val :=
(50, 40, 30, 35, 45, 55, 65, 85 );
bus_average(bus_statistics);
average <= bus_statistics.average_val;
END PROCESS;
The variable assignment to bus_statistics.bus_valfills in the appro-
priate bus utilization values to be used for the calculation. The next line is the
call to the bus_averageprocedure, which performs the averaging calculation.
Initially, the argument to the bus_averageprocedure is an input value, but
after the procedure has finished, the argument becomes an output value that
can be used inside the calling process. The output value from the procedure
is assigned to an output signal in the last line of the process.
SIDE EFFECTS Procedures have an interesting problem that is not
shared by their function counterparts. Procedures can cause side effects to
occur. A side effect is the result of changing the value of an object inside a
procedure when that object was not an argument to the procedure. For in-
stance, a signal of an architecture can be assigned a value from within a
procedure, without that signal being an argument passed into the proce-
dure. For instance, if two signals are not declared in the argument list of
a procedure, but are assigned from within a procedure called from the
current procedure, any assignments to these signals are side effects.
This is not a recommended method for writing a model. The debugging
and maintenance of a model of this type can be very difficult. This feature
was presented so the reader would understand the behavior if such a
model were examined.
Packages
The primary purpose of a package is to encapsulate elements that can be
shared (globally) among two or more design units. A package is a common
storage area used to hold data to be shared among a number of entities.