VHDL:	
  	
  
Func+ons	
  and	
  Procedures	
  
talarico@gonzaga.edu	
   1	
  
Subprograms	
  
• FUNCTION	
  
• PROCEDURE	
  
	
  
• FUNCTIONs	
  and	
  PROCEDUREs	
  have	
  the	
  same	
  
basic	
  purpose	
  
– store	
  commonly	
  used	
  pieces	
  of	
  code,	
  so	
  they	
  can	
  be	
  
reused	
  and	
  shared	
  
• VHDL	
  allow	
  FUNCTIONs	
  and	
  PROCEDUREs	
  to	
  be	
  
overloaded	
  
talarico@gonzaga.edu	
   2	
  
pieces	
  of	
  sequen+al	
  VHDL	
  code	
  
PROCESS	
  and	
  FUNCTION	
  vs.	
  PROCESS	
  
• FUNCTIONs	
  and	
  PROCEDUREs	
  are	
  mainly	
  intended	
  for	
  
LIBRARY	
  alloca0on	
  	
  
(although	
  it	
  is	
  possible	
  to	
  locate	
  them	
  in	
  the	
  main	
  code)	
  
	
  
	
  
	
  
• PROCESSes	
  are	
  intended	
  for	
  immediate	
  use	
  in	
  the	
  main	
  
code	
  
talarico@gonzaga.edu	
   3	
  
FUNCTION	
  vs.	
  PROCEDURE	
  
• FUNCTION	
  
– zero	
  or	
  more	
  input	
  parameters	
  and	
  a	
  single	
  return	
  value	
  
– The	
  input	
  parameters	
  can	
  only	
  be	
  constants	
  (default)	
  or	
  
signals	
  (variables	
  are	
  not	
  allowed)	
  
• PROCEDURE	
  
– Any	
  number	
  of	
  IN,	
  OUT,	
  and	
  INOUT	
  parameters	
  which	
  can	
  
be	
  constants,	
  signals,	
  variables	
  
– The	
  default	
  for	
  OUT	
  and	
  INOUT	
  parameters	
  is	
  variable	
  
• A	
  FUNCTION	
  is	
  called	
  as	
  part	
  of	
  an	
  expression,	
  while	
  a	
  
PROCEDURE	
  is	
  a	
  statement	
  on	
  its	
  own	
  
talarico@gonzaga.edu	
   4	
  
FUNCTION/PROCEDURE	
  loca+on	
  
talarico@gonzaga.edu	
   5	
  
FUNCTION	
  
talarico@gonzaga.edu	
   6	
  
FUNCTION:	
  Example	
  	
  
talarico@gonzaga.edu	
   7	
  
Example	
  of	
  Func+on	
  body:	
  
The	
  word	
  CONSTANT	
  	
  
can	
  be	
  omiYed	
  
do	
  not	
  enter	
  RANGE	
  or	
  	
  
TO/DOWNTO	
  
 	
  	
  	
  	
  	
  	
  	
  	
  	
  Examples:	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  FUNCTION	
  
talarico@gonzaga.edu	
   8	
  
Func+on	
  located	
  	
  
in	
  the	
  main	
  
Func+on	
  located	
  	
  
in	
  a	
  package	
  
PROCEDURE	
  
talarico@gonzaga.edu	
   9	
  
PROCEDURE:	
  example	
  
talarico@gonzaga.edu	
   10	
  
Example	
  of	
  PROCEDURE	
  body:	
  
std_logic_vector(7 downto 0);!
std_logic; SIGNAL b,c: IN std_logic;!
NOT	
  an	
  issue	
  with	
  	
  
PROCEDUREs	
  
STD_LOGIC;!
Examples:	
  
PROCEDURE	
  
talarico@gonzaga.edu	
   11	
  
PROCEDURE	
  located	
  	
  
in	
  the	
  main	
  
talarico@gonzaga.edu	
   12	
  
STD_LOGIC;!
Examples:	
  
PROCEDURE	
  
PROCEDURE	
  located	
  	
  
in	
  a	
  PACKAGE	
  
ASSERT	
  
talarico@gonzaga.edu	
   13	
  
Example:	
  

VHDL_functions and procedures_programming

  • 1.
    VHDL:     Func+ons  and  Procedures   talarico@gonzaga.edu   1  
  • 2.
    Subprograms   • FUNCTION   • PROCEDURE     • FUNCTIONs  and  PROCEDUREs  have  the  same   basic  purpose   – store  commonly  used  pieces  of  code,  so  they  can  be   reused  and  shared   • VHDL  allow  FUNCTIONs  and  PROCEDUREs  to  be   overloaded   talarico@gonzaga.edu   2   pieces  of  sequen+al  VHDL  code  
  • 3.
    PROCESS  and  FUNCTION  vs.  PROCESS   • FUNCTIONs  and  PROCEDUREs  are  mainly  intended  for   LIBRARY  alloca0on     (although  it  is  possible  to  locate  them  in  the  main  code)         • PROCESSes  are  intended  for  immediate  use  in  the  main   code   talarico@gonzaga.edu   3  
  • 4.
    FUNCTION  vs.  PROCEDURE   • FUNCTION   – zero  or  more  input  parameters  and  a  single  return  value   – The  input  parameters  can  only  be  constants  (default)  or   signals  (variables  are  not  allowed)   • PROCEDURE   – Any  number  of  IN,  OUT,  and  INOUT  parameters  which  can   be  constants,  signals,  variables   – The  default  for  OUT  and  INOUT  parameters  is  variable   • A  FUNCTION  is  called  as  part  of  an  expression,  while  a   PROCEDURE  is  a  statement  on  its  own   talarico@gonzaga.edu   4  
  • 5.
  • 6.
  • 7.
    FUNCTION:  Example     talarico@gonzaga.edu   7   Example  of  Func+on  body:   The  word  CONSTANT     can  be  omiYed   do  not  enter  RANGE  or     TO/DOWNTO  
  • 8.
                       Examples:                      FUNCTION   talarico@gonzaga.edu   8   Func+on  located     in  the  main   Func+on  located     in  a  package  
  • 9.
  • 10.
    PROCEDURE:  example   talarico@gonzaga.edu   10   Example  of  PROCEDURE  body:   std_logic_vector(7 downto 0);! std_logic; SIGNAL b,c: IN std_logic;! NOT  an  issue  with     PROCEDUREs  
  • 11.
    STD_LOGIC;! Examples:   PROCEDURE   talarico@gonzaga.edu   11   PROCEDURE  located     in  the  main  
  • 12.
    talarico@gonzaga.edu   12   STD_LOGIC;! Examples:   PROCEDURE   PROCEDURE  located     in  a  PACKAGE  
  • 13.