• Operators can be user-defined.
• Let us consider the pre-defined arithmetic operators seen earlier (+,- , *, /, etc.). They specify arithmetic operations between data of certain types (INTEGER, for example).
• For instance, the pre-defined ‘‘+’’ operator does not allow addition between data of type BIT.
• We can define our own operators, using the same name as the pre-defined ones.
• For example, we could use ‘‘+’’ to indicate a new kind of addition, this time between values of type BIT_VECTOR. This technique is called operator overloading.
• Example: Consider that we want to add an integer to a binary 1-bit number. Then the following FUNCTION could be used.
FUNCTION "+" (a: INTEGER, b: BIT) RETURN INTEGER IS
BEGIN
IF (b='1') THEN RETURN a+1;
ELSE RETURN a;
END IF;
END "+";
A call to the function above could thus be the
following:
SIGNAL inp1, outp: INTEGER RANGE 0 TO15;
SIGNAL inp2: BIT;
(...)
outp <= 3 + inp1 + inp2;
(...)
• In ‘‘outp<=3+inp1+inp2;’’, the first ‘‘+’’ is the pre- defined addition operator (adds two integers), while the second is the overloaded user-defined addition operator (adds an integer and a bit).
information shared by www.irvs.info