0% found this document useful (0 votes)
22 views2 pages

VHDL Functions

Functions in VHDL are small reusable code sections that perform an operation and return a single value based on input arguments in a combinational manner without delays or events. The example shows a function that reverses the bits of an 8-bit input vector and returns the result.

Uploaded by

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

VHDL Functions

Functions in VHDL are small reusable code sections that perform an operation and return a single value based on input arguments in a combinational manner without delays or events. The example shows a function that reverses the bits of an 8-bit input vector and returns the result.

Uploaded by

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

‌VHDL‌‌FUNCTIONS‌ 


 ‌
 ‌
Functions‌‌are‌‌part‌‌of‌‌a‌‌group‌‌of‌‌structures‌‌in‌‌VHDL‌‌called‌‌subprograms.‌‌Functions‌‌are‌‌small‌‌sections‌‌of‌‌code‌‌that‌‌  
perform‌‌an‌‌operation‌‌that‌‌is‌‌reused‌‌throughout‌‌your‌‌code.‌  ‌
Functions‌‌are‌‌used‌‌if‌‌all‌‌of‌‌the‌‌following‌‌conditions‌‌are‌‌true:‌‌    ‌
 ‌
•‌‌There‌‌are‌‌no‌‌delay,‌‌timing,‌‌or‌‌event‌‌control‌‌constructs‌‌that‌‌are‌‌present‌‌    ‌
•‌‌It‌‌returns‌‌a‌‌single‌‌value‌‌    ‌
•‌‌There‌‌is‌‌at‌‌least‌‌one‌‌input‌‌argument‌‌    ‌
•‌‌There‌‌are‌‌no‌‌output‌‌or‌‌inout‌‌arguments‌   ‌
•‌‌There‌‌are‌‌no‌‌non-blocking‌‌assignments‌‌    ‌
 ‌
In‌‌short,‌‌functions‌‌may‌‌implement‌‌only‌‌combinatorial‌‌behavior,‌‌i.e.‌‌they‌‌compute‌‌a‌‌value‌‌on‌‌the‌‌basis‌‌of‌‌the‌‌present‌‌value‌‌  
of‌‌the‌‌input‌‌arguments‌‌and‌‌return‌‌a‌‌single‌‌value.‌‌Each‌‌line‌‌of‌‌code‌‌in‌‌the‌‌function‌‌is‌‌executed‌‌sequentially‌‌(they‌‌are‌‌not‌‌
 
non-blocking).‌‌They‌‌are‌‌used‌‌in‌‌the‌‌right‌‌hand‌‌side‌‌of‌‌an‌‌assignment‌‌statement.‌‌Here‌‌is‌‌an‌‌example‌‌of‌‌a‌‌function‌‌  
definition‌‌and‌‌call.‌‌    ‌
 ‌
EXAMPLE:‌  ‌
 ‌
function‌‌i‌dentifier‌[‌ input‌‌port‌‌declarations]‌‌‌return‌t‌ype‌‌‌is‌  ‌
‌[variable‌‌declarations]‌‌   ‌
begin‌‌   ‌
‌function‌‌statements‌‌   ‌
end‌i‌dentifier‌  ‌
 ‌
To‌‌call‌‌a‌‌function,‌‌one‌‌needs‌‌to‌‌use‌‌the‌‌function‌‌identifier‌‌(with‌‌input(s)‌‌defined)‌‌as‌‌an‌‌assignment‌‌
   ‌
operand‌‌in‌‌a‌‌process‌‌block:‌‌    ‌
 ‌
Func_Out‌‌<=‌‌identifier‌‌(input);‌  ‌
 ‌
Here‌‌is‌‌code‌‌snippet‌‌showing‌‌how‌‌functions‌‌are‌‌used‌:  ‌‌ ‌
 ‌
function‌‌HAS_FUNCTION‌‌(  ‌‌ ‌
‌DIN‌‌:‌‌STD_LOGIC_VECTOR(7‌‌downto‌‌0);)‌‌   ‌
return‌‌STD_LOGIC_VECTOR‌‌is‌‌   ‌
‌variable‌‌k‌‌:‌‌integer‌‌:=‌‌0;‌‌   ‌
‌variable‌‌count‌‌:‌‌integer‌‌:=‌‌0;‌‌   ‌
‌variable‌‌reverse_bits‌‌:‌‌STD_LOGIC_VECTOR(7‌‌downto‌‌0)‌‌:=‌‌“00000000”;‌‌   ‌
begin‌‌   ‌
‌for‌‌k‌‌in‌‌0‌‌to‌‌7‌‌loop‌‌   ‌
‌reverse_bits(7‌‌–‌‌count)‌‌:=‌‌DIN(count);‌‌   ‌
‌count‌‌:=‌‌count‌‌+‌‌1;‌‌   ‌
‌end‌‌loop;‌‌   ‌
return‌‌reverse_bits;‌‌   ‌
end‌‌HAS_TASK;‌  ‌
 ‌
 ‌
 ‌
 ‌

You might also like