



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A chapter from 'vhdl in action' by martin that discusses subprograms in vhdl, including functions and procedures. The reasons for using subprograms, their issues, classes, ports and parameters, constraints, and examples. It also explains the rules for functions and procedures, subprogram overloading, and visibility.
Typology: Study notes
1 / 6
This page cannot be seen from the preview
Don't miss anything!




ECE 4514 Martin 2003 2
ECE 4514 Martin 2003 3
ECE 4514 Martin 2003 7
ECE 4514 Martin 2003 8
ECE 4514 Martin 2003 9
No WAIT statements allowed either directly or indirectly.
ECE 4514 Martin 2003 10
function BV2INT ( BVIN:Bit_vector( 7 downto 0 )) return Integer is variable TEMP: Integer := 0 ; begin for i in 0 to 7 loop if BVIN(i) = ' 1 ' then TEMP := TEMP + 2**i; end if; end loop; return TEMP; end BV2INT;
function DECODE3TO8 ( V: Bit_vector ( 2 downto 0 )) return Bit_vector is variable RESULT: Bit_vector( 7 downto 0 ) := "00000001"; begin if v(0) = ' 1 ' then RESULT := RESULT(6 downto 0) & ' 0 '; end if; if v(1) = ' 1 ' then RESULT := RESULT(5 downto 0) & " 00 "; end if; if v(2) = ' 1 ' then RESULT := RESULT(3 downto 0) & " 0000 "; end if; return RESULT; end DECODE3TO8;
Formal
architecture FPGA of CONTROL_UNIT is insert function definition here signal IAREG, IBREG, ICREG: Bit_vector(9 downto 0); signal AREGSEL, BREGSEL, CREGSEL: Bit_vector(2 downto 0); begin
IAREG <= "00" & DECODE3TO8( AREGSEL ); IBREG <= "00" & DECODE3TO8( BREGSEL ); ICREG <= "00" & DECODE3TO8( CREGSEL ); o o o
Actuals
ECE 4514 Martin 2003 19
ECE 4514 Martin 2003 20
ECE 4514 Martin 2003 21
procedure ADSU16P (signal A : in Bit_vector(15 downto 0); signal B : in Bit_vector(15 downto 0); signal CIN : in Bit; signal ADD : in Bit; signal S : out Bit_vector(15 downto 0); signal OFL : out Bit) is variable MS : Bit_vector ( 15 downto 0 ); variable MB : Bit_vector ( 15 downto 0 ); variable CARRY : Bit; begin o
Formals
Internal variables visible only inside procedure.
ECE 4514 Martin 2003 22
for i in 0 to 15 loop MS(i) := MB(i) xor (A(i) xor CARRY); CARRY := (MB(i) and A(i)) or ( (MB(i) and CARRY) or (A(i) and CARRY)); end loop; -- compute overflow bit if (MB(15) = A(15)) then OFL <= MB(15) xor MS(15); else OFL <= ' 0 '; end if; S <= MS; end ADSU16P;
ECE 4514 Martin 2003 25
ECE 4514 Martin 2003 26
ECE 4514 Martin 2003 27
ECE 4514 Martin 2003 28
All signals in this example are assumed to be of type BIT