Package and Sub-Programs

Updated on 2017/07/29 17:02

Syllabus

  • Packages, Sub programs

Package

Package Declaration Format

package package_name is
... exported constant declarations
... exported type declarations
... exported subprogram declarations
end package_name;

Examples

Example 1

package ee530 is
constant maxint: integer := 16#ffff#;
type arith_mode_type is (signed, unsigned);
function minimum(constant a,b: in integer) return integer;
end ee530;
Package body format
package body package_name is
... exported subprogram bodies
... other internally-used declarations
end package_name;

Example 2

package body ee530 is
function minimum (constant a,b: integer) return integer is
variable c: integer; -- local variable
begin
if a < b then
c := a;-- a is min
else
c := b;-- b is min
end if;
return c;-- return min value
end;
end ee530;

Sub-Programs

A  subprogram defines a sequential algorithm that performs a certain computation. Subprograms can be overloaded.
There are two kinds of subprograms

  • Functions
  • Procedures

Functions

  • Function name can be an operator
  • Arbitrary number of input parameters
  • Exactly one return value
  • No WAIT statement allowed
  • Function call &hArr; VHDL expression
  • Computes a sinle value
  • Executes in zero simulation time

Procedures

  • Arbitrary number of parameters of any possible direction (in/out/inout)
  • RETURN statement optional (no return value!)
  • Procedure call &hArr; VHDL statement
  • Can computes several values
  • May not execute in zero simulation time,depending on whether it has a wait statement or not
     

References

  • Edited and Created by Prof Hrishikesh Dhanwate, JSPM'S ICOER, Wagholi ,Pune
  • WikiNote Foundation
Tags:
Created by HrishikeshDhanawate on 2017/07/28 19:07