VHDL Tutorial

Procedure parameters in VHDL
Introduction
Fundamental concepts
Modelling concepts
Elements of behaviour
Elements of structure
Analysis elaboration
Lexical elements
Identifiers
Numbers
Characters and strings 
Syntax descriptions
Constants and variables
Scalar type
Integer types
Floating point types
Time type
Enumeration types
Character types
Boolean type 
Bits type
Standard logic
Sequential statements
Case statements
Loop and exit statements
Assertion statements
Array types & array operations
Architecture bodies
Entity declarations
Behavioral descriptions 
Wait statements
Delta delays
Process statements
Conditional signal assignment 
Selected signal assigment
Structural descriptions
Library and library clauses
Procedures
Procedure parameters

Signal parameters
Default values
Unconstrained array parameter
Functions
Package declarations and bodies
Subprograms in package
Use clauses
Resolved signals and subtypes
Resolved signals and ports
Parameterizing behavior
Parameterizing structure

Procedure Parameters

 

Now that we have looked at the basics of procedures, we will discuss procedures that include parameters.  When we write a parameterized procedure, we include informa- tion in the parameter list about the parameters to be passed to the procedure.   The syntax rule for a procedure declaration on page 59 shows where the parameter list fits in.   Following is the syntax rule for a parameter list:

interface_list

( [ constant I variable I signal ]

identifier { , … } : [ mode ] subtype_indication

[ := static_expression ]  ) { ; … }

mode in I out I inout

 

The parameter list defines the formal parameters of the procedure.   We can think of them as placeholders that stand for the actual parameters, which are to be supplied by the caller when it calls the procedure.   Since the syntax rule for a parameter list is quite complex, let us start with some simple examples and work up from them.

 

Want To have highly paid VLSI jobs ?? then you may contact at

Contact : webmaster@freehost7com

EXAMPLE

 

First, let’s rewrite the procedure do_arith_op, from Figure 5-1, so that the func- tion code is passed as a parameter.   The new version is shown in Figure 5-2.   In the parameter interface list we have  identified one formal parameter named  op. The mode of the formal parameter is in, indicating that it is used to pass informa- tion into the procedure from the caller.   The type of the parameter is func_code, indicating that the operations performed on the formal parameter must be appro- priate for a value of this type and that the caller may only pass a value of this type

as an actual parameter.

Now that we have parameterized the procedure, we can call it from different places  passing  different  function  codes  each  time For  example,  a  call  at  one place might be

 

do_arith_op ( add );

 

The procedure call simply includes the actual parameter value in parentheses.  In this case we pass the literal value add as the actual parameter At another place

in the model we might pass the value of the signal func shown in the model in

Figure 5-1:

 

do_arith_op ( func );

 

 

FIGURE 5-2

 

procedure do_arith_op ( op : in func_code ) is

variable result : integer;

begin

case op is

when add =>

result := op1 + op2;

when subtract =>

result := op1 – op2;

end case;

dest  <=  result after Tpd;

Z_flag  <=  result = 0 after Tpd;

end procedure do_arith_op;

 

A procedure to perform an arithmetic operation, parameterized by the kind of operation.

 

 

 

The syntax rule for a parameter list also shows us that we can specify the class of

a formal parameter, namely, whether it is a constant, a variable or a signal within the procedure If the mode of the parameter is in, the class is assumed to be constant, since a constant is an object that cannot be updated by assignment.  Usually we simply leave out  the  keyword  constant,  relying on the  mode to make our  intentions  clear. For an in mode constant-class parameter, we write an expression as the actual param- eter.

Let us now turn to formal parameters of mode out.  Such a parameter lets us trans- fer information out from the procedure back to the caller.   Here is an example.

 

EXAMPLE

 

The procedure in Figure 5-3 performs addition of two unsigned numbers rep- resented  as  bit  vectors  of  type  word32,  which  we  assume  is  defined  elsewhere. The procedure has two in mode parameters a and b, allowing the caller to pass two bit-vector values.  The procedure uses these values to calculate the sum and overflow  flag.   Within  the  procedure,  the  two  out  mode  parameters,  result  and overflow,  appear  as  variables.   The  procedure  performs  variable  assignments  to update their values, thus transferring information back to the caller.

 

FIGURE 5-3

 

procedure addu ( a, b : in word32;

result : out word32;  overflow : out boolean ) is variable sum : word32;

variable carry : bit := '0';

begin

for index in sum'reverse_range loop

sum(index) := a(index) xor b(index) xor carry;

carry := ( a(index) and b(index) ) or ( carry and ( a(index) xor b(index) ) );

end loop;

result := sum;

overflow := carry = '1';

end procedure addu;

 

 

A procedure to add two bit vectors representing unsigned integers.

 

A call to this procedure may appear as follows:

 

variable PC, next_PC : word32;

variable overflow_flag : boolean;

…

addu ( PC, X"0000_0004", next_PC, overflow_flag);

 

 

 

In the above example, the out mode parameters are of the class variable Since this class is assumed for out parameters, we usually leave out the class specification variable.  The mode out indicates that the only way the procedure may use the formal parameters  is  to  update  them  by  variable  assignment;  it may  not  read  the  values  of the parameters For an out mode, variable-class parameter, the caller must supply a variable as an actual parameter.

The third mode we can specify for formal parameters is inout, which is a combi- nation of in and out modes.  It is used for objects that are to be both read and updated by a procedure As with out parameters, they are assumed to be of class variable if the class is not explicitly stated For inout mode variable parameters, the caller sup- plies a variable as an actual parameter.  The value of this variable is used to initialize the  formal  parameter,  which  may  then  be  used  in  the  statements  of  the  procedure. The procedure may also perform variable assignments to update the formal parame- ter.  When the procedure returns, the value of the formal parameter is copied back to the actual parameter variable, transferring information back to the caller.

 

 

 

 

 

 

 

 

 

 

 

Home