Subprograms and Overloading - PowerPoint PPT Presentation

1 / 31
About This Presentation
Title:

Subprograms and Overloading

Description:

Procedures may not execute in zero simulation time if there are wait statements in them. ... sub. add. Op. 3. 3. 3. 3. X1. Subprogram overloading ... – PowerPoint PPT presentation

Number of Views:99
Avg rating:3.0/5.0
Slides: 32
Provided by: personal
Category:

less

Transcript and Presenter's Notes

Title: Subprograms and Overloading


1
Subprograms and Overloading
CpE487
2
Subprograms
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

3
Variables 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.

4
Functions example

000gt0 001gt1 010gt2 011gt3
100gt4 101gt5 110gt6 111gt7
5
Where do we put functions
?
?
?
?
6
Where do we put functions
no
no
Can be seen in the architecture
Good
Can be seen in the process
Good
7
The function example
8
The function example
9
The function example
10
The function example
Using Bit_vector
Using integer
11
The lab example
Using Bit_vector
Using integer
12
another function example
13
Function
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
14
Procedures
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.
15
Procedure example
16
Procedure 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
17
Procedure example
Concurrent components
18
Procedure example
19
Subprogram 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
20
Subprogram overloading
If two overloaded subprograms have the same
parameter types and result types, it is possible
for one subprogram to hid the other subprogram.
21
Subprogram overloading
Different number of parameters
Function call
22
Subprogram 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)

23
Operator overloading
Operators can be overloaded.
24
Packages 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

25
Revisit the function example
26
Put the function into a package
27
Create a library
28
Move the package in the library
29
Move the package in the library
30
Use the function in the package
Mylib is a created library and package pkgex is
in it.
31
The example simulation result
Write a Comment
User Comments (0)
About PowerShow.com