210 Chapter Eight
result := result + 8;
END IF;
RETURN result;
END convert_addr;
END p_addr_convert;
This package declares three functions that convert 2, 3, or 4 input bits
into integer representation. Each function is named the same, but the
appropriate function is called depending on the number of input arguments
that are passed to the function. If 2 bits are passed to the function, then
the function with two arguments is called. If 3 bits are passed, the func-
tion with three arguments is called, and so on.
Following is an example using these functions:
LIBRARY IEEE;
USE IEEE.std_logic_1164.ALL;
USE WORK.p_addr_convert.ALL;
ENTITY test IS
PORT(i0, i1, i2, i3 : in std_logic);
END test;
ARCHITECTURE test1 OF test IS
SIGNAL int1, int2, int3 : INTEGER;
BEGIN
-- uses first function
int1 <= convert_addr(i0, i1);
-- uses second function
int2 <= convert_addr(i0, i1, i2);
-- uses third function
int3 <= convert_addr(i0, i1, i2, i3);
END test1;
The first call to the convert_addrfunction has only two arguments in
the argument list, and therefore the first function in package
p_addr_convertis used. The second call has three arguments in its
argument list and calls the second function. The last call matches the
third function from package p_addr_convert.
Overloading Operators
One of the most useful applications of overloading is the overloading of
operators. The need for overloading operators arises because the operators