VHDL Tutorial

Functions in VHDL
Fundamental concepts
Modelling concepts
Elements of behaviour
Elements of structure
Analysis elaboration
Lexical elements
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
Procedure parameters
Signal parameters
Default values
Unconstrained array parameter

Package declarations and bodies
Subprograms in package
Use clauses
Resolved signals and subtypes
Resolved signals and ports
Parameterizing behavior
Parameterizing structure



Let us now turn our attention to the second kind of subprogram in VHDL: functions. The syntax rule for a function declaration is very similar to that for a procedure dec- laration:



function identifier [ ( parameter_interface_list ) ] return type_mark is

{ subprogram_declarative_item }


{ sequential_statement }

end [ function ] [ identifier ] ;


The  identifier  in  the  declaration  names  the  function.   It  may  be  repeated  at  the end of the declaration.  Unlike a procedure subprogram, a function calculates and re- turns a result that can be used in an expression The function declaration specifies the type of the result after the keyword return.  The parameter list of a function takes the same form as that for a procedure, with two restrictions.   First, the parameters of

a function may not be of the class variable.  If the class is not explicitly mentioned, it

is assumed to be constant Second, the mode of each parameter must be in If the mode is not explicitly specified, it is assumed to be in Like a procedure, a function can declare local items in its declarative part for use in the statements in the function body.

A  function  passes  the  result  of  its  computation  back  to  its  caller  using  a  return statement, given by the syntax rule


return_statement return expression ;


A function must include at least one return statement.  The first to be executed causes the function to complete and return its result to the caller.   A function cannot simply run  into  the  end  of  the  function  body,  since  to  do  so  would  not  provide  a  way  of specifying a result to pass back to the caller.

A function call looks exactly like a procedure call.   The syntax rule is function_call function_name [ ( parameter_association_list ) ]

The difference is that a function call is part of an expression, rather than being a se- quential statement on its own, like a procedure call.




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

Contact : webmaster@freehost7com

The function in Figure 5-7 determines the number represented in binary by a bit-vector value.




function bv_to_natural ( bv : in bit_vector ) return natural is

variable result : natural := 0;


for index in bv'range loop

result := result * 2 + bit'pos(bv(index));

end loop;

return result;

end function bv_to_natural;


A function that converts the binary representation of an unsigned number to a numeric value.


As an example of using this function, consider a model for a read-only mem- ory, which represents the stored data as an array of bit vectors, as follows:


type rom_array is array (natural range 0 to rom_size1)

of bit_vector(0 to word_size1);

variable rom_data : rom_array;


If the model has an address port that is a bit vector, we can use the function to convert the address to a natural value to index the ROM data array, as follows:


data <= rom_data ( bv_to_natural(address) ) after Taccess;