Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
1Activity
0 of .
Results for:
No results containing your search query
P. 1
Unit-3(comp)

Unit-3(comp)

Ratings: (0)|Views: 4|Likes:
Published by Shipra Gupta

More info:

Published by: Shipra Gupta on Aug 20, 2011
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less

12/09/2013

pdf

text

original

 
Unit-3 Subprogram and Packages:
Subprogram and Overloading:
Functions and Procedures with simple examples,subprogram overloading, Operator Overloading.
Electronics Syllabus:Packages and Libraries:
Package Declaration, Package Body, Design File, DesignLibraries, Order of analysis, implicit visibility, explicit visibility, Library Clause and UseClause.
Advanced Features:
Entity Statements, Generate Statements, Attributes, Aggregatetargets, ports and their behaviour.
3.1 Subprogram and Overloading:
There are two kinds of subprograms: proceduresand functions. Both procedures and functions written in VHDL must have a body andmay have declarations.Procedures perform sequential computations and return values in global objects or bystoring values into formal parameters.Functions perform sequential computations and return a value as the value of thefunction. Functions do not change their formal parameters.Subprograms may exist as just a procedure body or a function body. Subprograms mayalso have a procedure declarations or a function declaration.When subprograms are provided in a package, the subprogram declaration is placed inthe package declaration and the subprogram body is placed in the package body.
3.1.1 Functions:
A function is a subprogram that is passed parameters and returns asingle value. Functions are primarily used in expressions.
Syntax:function designator [ ( formal_parameter_list ) ] return type_mark 
Function Designator is the identifier or name of the function. Formal parameter list isoptional. Type mark represents the data type in which the function returns itsvalue.
Example:-- Convert bit_vector to IEEE std_logic_vector format-- (attributes LENGTH and RANGE are described below)function bv2slv (b:bit_vector) return std_logic_vector isvariable result: std_logic_vector(b'LENGTH-1 downto 0);beginfor i in result'RANGE loopcase b(i) iswhen '0' => result(i) := '0';when '1' => result(i) := '1';end case;end loop;
 
return result;end;-- Convert bit_vector to unsigned (natural) valuefunction b2n (B: bit_vector) return Natural isvariable S: bit_vector(B'Length - 1 downto 0) := B;variable N: Natural := 0;beginfor i in S'Right to S'Left loopif S(i) = '1' thenN := N + (2**i);end if;end loop;return N;end;3.1.2 Function Calls:
 
signal databus: vector4(15 downto 0);signal internal: bit_vector (15 downto 0);variable x: integer;....databus <= bv2slv (internal);
A subprogram declaration in this form simply names the subprogram and specifies the parameters required. The body of statements defining the behaviour of the subprogram isdeferred. For function subprograms, the declaration also specifies the type of the resultreturned when the function is called. This form of subprogram declaration is typicallyused in package specifications, where the subprogram body is given in the package body,or to define mutually recursive procedures. The syntax for specifying the formal parameters of a subprogram is:
Syntax:formal_parameter_list ::=
 parameter_
interface_listinterface_list ::= interface_element { ; interface_element }interface_element ::= interface_declarationinterface_declaration ::= interface_constant_declaration| interface_signal_declaration | interface_variable_declarationinterface_constant_declaration ::= [ constant ] identifier_list : [ in ]subtype_indication [ :=
 static_
expression ]interface_variable_declaration ::=[ variable ] identifier_list : [ mode ] subtype_indication [ :=
 static_
expression ]3.1.3
 
Procedure:
A procedure is a subprogram that is passed parameters and may returnvalues via a parameter list.
 
Example:
 
procedure proc_name (signal clk: in vlbit;constant d: in vlbit;signal data: out vlbit) is... local variable declarations ...begin... sequence of statements ...end proc_name;Procedure call: proc_name(clk1, d1, dout);
The procedure is a form of subprograms. It contains local declarations and a sequence of statements. Procedures can be called in any place of the architecture. The proceduredefinition consists of two parts:
The procedure declaration
The procedure body
3.1.3.1 Procedure Declaration:
Procedure declaration consists of procedure name andthe formal parameter list. It is required when the procedure is called. In the procedurespecification, the identifier and the formal parameter list follow the reserved word
procedure
.Bjects, classes, constants, variables, signals and files can be used as formal parameters.The class of each parameter is specified by the appropriate reserved word, unless thedefault class can be assumed. In case of constants, variables and signals, the parameter mode determines the direction of the information flow and it decides which formal parameters can be read or written inside the procedure. For parameters of the file
type_name
, no mode is assigned. There are three modes available:
in, out and inout
.When
in
mode is declared and object class is not defined, then by default it is assumedthat the object is a constant. In case of 
inout
and
out
modes, the default class is avariable. When a procedure is called, formal parameters are substituted by actual parameters. If a formal parameter is a constant, then the actual parameter must be anexpression. In case of formal parameters such as signal, variable and file, the actual parameters must be objects of the same class. A procedure can also be declared withoutany parameters.
3.1.3.2 Procedure Body:
Procedure body consists of the local declarations andstatements required to execute the procedure. Procedure body defines the procedure’salgorithm composed of sequential statements. When the procedure is called, it startsexecuting the sequence of statements declared inside the procedure body.The procedure body consists of the subprogram declarative part. After the reserved word
is
the subprogram statement part is placed between the reserved words
begin
and
end
.The keyword
procedure
and the
procedure name
may optionally follow the endreserved word.Declarations of a procedure are local to this declaration and can declare subprogramdeclarations, subprogram bodies, types, subtypes, constants, variable, files, aliases,

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->