Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
9 views18 pages

Naren - Procedure and Function

The document provides an overview of VHDL subprograms, specifically focusing on procedures and functions. It outlines their definitions, types, declarations, and differences, emphasizing that functions return a value while procedures do not. Additionally, it includes examples of procedures and functions in VHDL, illustrating their usage in design.

Uploaded by

rohitasapure111
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPSX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views18 pages

Naren - Procedure and Function

The document provides an overview of VHDL subprograms, specifically focusing on procedures and functions. It outlines their definitions, types, declarations, and differences, emphasizing that functions return a value while procedures do not. Additionally, it includes examples of procedures and functions in VHDL, illustrating their usage in design.

Uploaded by

rohitasapure111
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPSX, PDF, TXT or read online on Scribd
You are on page 1/ 18

VLSI Design

Procedure and Functions


( Unit-II )

Subject In Charge

Narendra L Lokhande
Department of Electronics and Telecommunication
R C Patel Institute of Technology, Shirpur,
Dist: Dhule, Maharashtra

Email: [email protected]

Prepared By: Narendra L Lokhande 1


Subprograms
• Like other programming languages, VHDL provides
subprogram facilities in the form of procedures and
functions.

• The features of subprograms are such that they can be


written once and called many times.

• They can be recursive and thus can be repeated from


within the scope.

• The major difference between procedure and function


is that the function has a return statement but a
procedure does not have a return statement.
Prepared By: Narendra L Lokhande 2
Types of Subprograms
• VHDL provides two sub-program constructs:

 Procedure: generalization for a set of statements.


 Function: generalization for an expression.

Prepared By: Narendra L Lokhande 3


Declarations of procedures and function
Both procedure and functions can be
declared in the declarative parts of:

 Entity
 Architecture
 Process
 Package interface
 Other procedure and functions

Prepared By: Narendra L Lokhande 4


Formal and actual parameters
• The variables, constants and signals specified in the
subprogram declaration are called formal parameters.

• The variables, constants and signals specified in the


subprogram call are called actual parameters.

• Formal parameters act as placeholders for actual


parameters.

Prepared By: Narendra L Lokhande 5


Concurrent and sequential programs
• Both functions and procedures can be either concurrent or
sequential

• Concurrent functions or procedures exists outside process


statement or another subprogram

• Sequential functions or procedures exist only in process


statement or another subprogram statement.

Prepared By: Narendra L Lokhande 6


Procedure
• A procedure is a subprogram that defined as
algorithm for computing values or exhibiting
behavior.

• Procedure call is a statement, which encapsulates


a collection of sequential statements into a single
statement.

Prepared By: Narendra L Lokhande 7


Procedure cont..
• Procedure declarations can be nested
– Allows for recursive calls

• Procedures can call other procedures

• Procedure must be declared before use. It can be declared


in any place where declarations are allowed, however the
place of declaration determines the scope

• Cannot be used on right side of signal assignment


expression since doesn’t return value

Prepared By: Narendra L Lokhande 8


Syntax for Procedure
procedure identifier [ parameter_interface
_list ] is
subprogram_declarative_part
begin

sequential_statement

End identifier ;

parameter_interface _list <=


( [ constant | variable | Prepared
signal ] identifier
By: Narendra L Lokhande { , . . . }) 9
Example_1

PROCEDURE p_1(variable x, y: inout real);

PROCEDURE p_2 (constant in1: in integer; variable o1: out integer);

PROCEDURE p_3 (signal sig: inout std_logic);

Prepared By: Narendra L Lokhande 10


Example_2

procedure transcoder_1 (variable value: inout bit_vector (0 to 7)) is


begin
case value is

when “00000000” => value : = “01010101”;


when “01010101” => value : = “00000000”;
when others => value : = “11111111”;

End case;
End transcoder_1;
Prepared By: Narendra L Lokhande 11
VHDL Full Adder Using Procedure
library IEEE; Begin
Use IEEE.STD_LOGIC_1164.ALL; process (x, y, cin)
variable sum1, c1, c2, tem1,
Entity full_add is
port (x, y, cin : in std_logic; tem2 : std_logic;
sum, cout : out std_logic); Begin
End full_add;
Haddr (sum1, c1, y, cin);
Architecture two_halfs of full_add is Haddr (tem1, c2, sum1, x);
procedure Haddr(sh, ch : out std_logic; tem2 := c1 OR c2;
ah, bh : in std_logic) is
sum <= tem1;
Begin cout <= tem2;

sh := ah xor bh; End process;


ch := ah and bh;

End Haddr; End two_halfs;


Prepared By: Narendra L Lokhande 12
VHDL N-Bit Ripple Carry Adder Using Procedure
Library IEEE;
Use IEEE.STD_LOGIC_1164.ALL; Begin
process (x, y, cin)
Entity adder_ripple is variable c1, c2, tem1, tem2 : std_logic;
Generic (N : integer := 3); variable cint : std_logic_vector (N+1 downto 0);
port (x, y : in std_logic_vector (N downto 0); variable sum1 : std_logic_vector (N downto 0);
cin : in std_logic;
sum : out std_logic_vector (N downto 0); Begin
cout : out std_logic); cint(0) := cin;
End adder_ripple;
for i in 0 to N loop
Architecture adder of adder_ripple is
Faddr (sum1(i), cint(i+1), x(i), y(i), cint(i));
procedure Faddr(sf, cof : out std_logic;
af, bf, cinf : in std_logic) is End loop;

Begin sum <= sum1;


cout <= cint(N+1);
sf := af XOR bf XOR cinf;
cof := (af AND bf) OR (af AND cinf) OR (bf AND End process;
cinf);
End adder;
Prepared By: Narendra L Lokhande 13
End Faddr;
Functions

• A function call is the subprogram of the form that


returns a value.

• It can also be defined as a subprogram that either


defines a algorithm for computing values or describes a
behavior.

• The important feature of the function is that they are


used as expressions that return values of specified
type. This is the main difference from procedures

• The results return by a function can be either scalar or


complex type. Prepared By: Narendra L Lokhande 14
Example
function func_1 (A, B, X : real) return real;
function “*” (a, b: integer_new) return integer_new;
function add_signals (signal in1, in2: real) return real;

• The first function name above is called func_1, it has three


parameters A,B and X, all of the REAL types and returns a value also
of REAL type.

• The second function defines a new algorithm for executing


multiplication. Note that the operator is enclosed in double quotes
and plays the role of the function name.

• The third is based on the signals as input parameters, which is


denoted by the reserved word signal preceding the parameters.
Prepared By: Narendra L Lokhande 15
Example-2
function transcod_1(value: in std_logic_vector (0 to 7)) return

std_logic_vector is
Begin
case value is

when “00000000” => return “01010101”;


when “01010101” => return “00000000”;
when others => return “11111111”;

End case;

End transcod_1;

Prepared By: Narendra L Lokhande 16


VHDL Function to Find the Greater of Two Signed Numbers
library IEEE; Begin
use IEEE.STD_LOGIC_1164.ALL;
process (x, y)
use IEEE.NUMERIC_STD.ALL;
Begin
Entity greater_2 is z <= grt (x, y);
port (x, y : in signed (3 downto 0);
z : out signed (3 downto 0));
End process;
End greater_2;

Architecture greater of greater_2 is End greater;


function grt (a, b : signed (3 downto 0)) return signed is
variable temp : signed (3 downto 0);
Begin
if (a >= b) then
temp := a;
else
temp := b;
end if;
return temp;
End grt;
Prepared By: Narendra L Lokhande 17
Difference Between Function and Procedure

1) Returns only one argument. 1) It can return more than one


argument
2) Lists parameters are constant 2) List parameters can be in / out/
by default but can be overridden inout. It can be only in for
by using signal. constant and can be out/inout
for variable.
3) function by itself is not
3) procedure is a complete
complete statement.
statement
4) function has two parts: function 4) procedure has two parts:
declaration and function call. procedure declaration and
procedure call.

Prepared By: Narendra L Lokhande 18

You might also like