Title: Subprograms and Overloading
1Subprograms and Overloading
CpE487
2Subprograms
A subprogram defines a sequential algorithm that
performs a certain computation. Function Compu
tes a single value. executes in zero simulation
time Procedure can computes several
values may not execute in zero simulation time
3Variables in Subprograms
Variables in a subprogram are created and
initialized every time the subprogram is called.
They remain in existence until the subprogram
completes. Variables in a process statement,
which get initialized only once at the start of
simulation and persist throughout the entire
simulation.
4Functions example
000gt0 001gt1 010gt2 011gt3
100gt4 101gt5 110gt6 111gt7
5Where do we put functions
?
?
?
?
6Where do we put functions
no
no
Can be seen in the architecture
Good
Can be seen in the process
Good
7The function example
8The function example
9The function example
10The function example
Using Bit_vector
Using integer
11The lab example
Using Bit_vector
Using integer
12another function example
13Function
Pure function Returns the same value each time
the function is called with the same set of
actuals Impure function Potential returns
different values each time it is called with the
same set of actuals
14Procedures
Procedures allow decomposition of large behaviors
into modular sections. In contrast to a function,
a procedure can return zero or more values using
mode out and inout. Procedures may not execute
in zero simulation time if there are wait
statements in them.
15Procedure example
16Procedure example
x1
3 bits
3 bits
x2
6 bits
z1
op
2 bits
Op z1 00 x1x2 01 x1-x2 10 x1x2 11 x1/x2
17Procedure example
Concurrent components
18Procedure example
19Subprogram overloading
Sometimes it is convenient to have two or more
subprograms with the same name. In such a case,
the subprogram name is said to be overloaded.
Function call
20Subprogram overloading
If two overloaded subprograms have the same
parameter types and result types, it is possible
for one subprogram to hid the other subprogram.
21Subprogram overloading
Different number of parameters
Function call
22Subprogram overloading
- Distinguish between overloaded subprograms
- subprogram name
- number of actuals
- types and order of actuals
- names of formal prameters( if named association
is used) - result type(for fucntion)
23Operator overloading
Operators can be overloaded.
24Packages and Libraries
- Packages provides a convenient mechanism to store
and share declarations that are common across
many design units. - type and subtype declarations
- Constant declarations
- File and alias declarations
- Functions and procedures
25Revisit the function example
26Put the function into a package
27Create a library
28Move the package in the library
29Move the package in the library
30Use the function in the package
Mylib is a created library and package pkgex is
in it.
31The example simulation result