Make your own free website on Tripod.com
Factorial    Example    in    VHDL

Library IEEE;
use IEEE.std_logic_1164.all;

Entity rec is
end rec;

Architecture A_rec  of rec is

	Function Factorial( Number : Integer;Initial : Integer:= 1 ) return integer is
		Variable Temp_No : Integer;
		Variable Sum : Integer;
		Variable temp: integer;
	begin
		Sum := Initial;
		Temp_No := Number;
		if (Temp_No > 1) then
		 Sum := Sum * ( Temp_No)* (Temp_No-1);
		 if ( (Temp_No - 2) > 1) then
		   Temp_No := Temp_No - 2;
			 temp:=Factorial(Temp_No,Sum);
		 else
			 temp := sum;
		 end if;
		end if;
		return temp;
	end Factorial;
-------------------------------------------------------------------------
----
-------------------------------------------------------------------------
begin
	Recursive_P :Process
	  variable Fact_no : integer:= 5;
		variable Result : integer;
	begin
		Result := Factorial(Fact_no);
		wait;
	end process;
end A_rec;

Back To Main Page: