Académique Documents
Professionnel Documents
Culture Documents
Ricardo Beltrán
Electronic Engineering
Digital Systems I
Functions and procedures are known as subprograms.
From a construction point of view , they are very
similar to those processes .
However, from a viewpoint of application, there is a
fundamental difference between processes, functions
or procedures: while the former is aimed at immediate
use within the main code , the others are intended to
use in libraries , that is, its purpose is to store common
pieces of code, so they can be reused or shared with
other projects .
However , if desired, a function or procedure can also
be placed within the main code.
A function is a sequential code section .
Its purpose is to create code to deal with common design
problems, such as:
Data type conversion
Logical operations
Arithmetic Calculations
New operators and attributes
A function is a sequential code section .
When you write code like function , it can be reused and
shared
The functions are similar to processes, since they can be
used in both statements (IF, WAIT , CASE , LOOP ) except
WAIT
Two other prohibitions are a function declaration and use of
signal components.
To make and use a function, two parts are necessary : the same function
( function body ) and the call to the function. Its syntax is as follows:
In this syntax, <parameter list> contains the input parameters , that is:
<parameter list>= [CONSTANT] constant_name: constant_type;
<parameter list>= SIGNAL signal_name: signal_type
Types can be any of the synthesizable (boolean , bit , std_logic , integer, etc )
. However, it is not necessary to specify the range . On the other hand , there
is only one return value, whose type is specified with data_type
This feature, called f1, takes three parameters : a, b and
c.
a and b are constants ( note that the constant word can
be omitted because it is the default object ) , while c is a
sign
a and b are integers , while c is the type
std_logic_vector .
Note that no range for integer values (a and b ) or to
the logic ( c ) is specified .
The output parameter (which is only one) is a boolean .
A function is called as part of an expression.
The expression obviously can appear by itself or associated
with a statement ( either simultaneously or sequentially ) .
Examples of function calls: