Anissa85
Newbie level 1
I want to program a function but it contains many iteration, i do it like this:
LIBRARY ieee ;
USE ieee.numeric_std.all ;
USE ieee.std_logic_1164.all ;
USE ieee.std_logic_arith.all ;
-----------------------------------
package pack_A is
Constant N: integer := 7;
function Substraction ( rin: STD_LOGIC; A: STD_LOGIC_VECTOR (N downto 0); B: STD_LOGIC_VECTOR (N downto 0)) return STD_LOGIC_VECTOR;
end package;
----------------------------------------------
package body pack_A is
function Substraction ( rin: STD_LOGIC; A: STD_LOGIC_VECTOR (N downto 0); B: STD_LOGIC_VECTOR (N downto 0)) return STD_LOGIC_VECTOR is
variable r: STD_LOGIC_VECTOR (N+1 downto 0):=(others => '0');
variable s: STD_LOGIC_VECTOR (N+1 downto 0):=(others => '0');
variable i: integer :=2;
begin
r(0) := rin;
s(0) := a(0) xor b(0) xor r(0);
r(1) := ((not a(0)) and (b(0) or r(0))) or (b(0) and r(0));
if ( i > 0) then
s(i) := a(i) xor b(i) xor r(i);
r(i+1) := ((not a(i)) and (b(i) or r(i))) or (b(i) and r(i));
i := i+1;
if (i=N+1) then
s(N+1) := r(N+1);
end if;
end if;
return s;
end Substraction;
--------------------------------------------------------------
end pack_A;
But it given't any result, however when i did it in process (component) it give result.
Please i need help, THANKS.
LIBRARY ieee ;
USE ieee.numeric_std.all ;
USE ieee.std_logic_1164.all ;
USE ieee.std_logic_arith.all ;
-----------------------------------
package pack_A is
Constant N: integer := 7;
function Substraction ( rin: STD_LOGIC; A: STD_LOGIC_VECTOR (N downto 0); B: STD_LOGIC_VECTOR (N downto 0)) return STD_LOGIC_VECTOR;
end package;
----------------------------------------------
package body pack_A is
function Substraction ( rin: STD_LOGIC; A: STD_LOGIC_VECTOR (N downto 0); B: STD_LOGIC_VECTOR (N downto 0)) return STD_LOGIC_VECTOR is
variable r: STD_LOGIC_VECTOR (N+1 downto 0):=(others => '0');
variable s: STD_LOGIC_VECTOR (N+1 downto 0):=(others => '0');
variable i: integer :=2;
begin
r(0) := rin;
s(0) := a(0) xor b(0) xor r(0);
r(1) := ((not a(0)) and (b(0) or r(0))) or (b(0) and r(0));
if ( i > 0) then
s(i) := a(i) xor b(i) xor r(i);
r(i+1) := ((not a(i)) and (b(i) or r(i))) or (b(i) and r(i));
i := i+1;
if (i=N+1) then
s(N+1) := r(N+1);
end if;
end if;
return s;
end Substraction;
--------------------------------------------------------------
end pack_A;
But it given't any result, however when i did it in process (component) it give result.
Please i need help, THANKS.