P
Parthav
Guest
Hello friends,
I'm not the novice for the VHDL coding but i've not came across adding
the use work.my_package.all in the initial library declaration part.
Now i want help on that what exactly this statement do? Also if i'm
making a function in the package body where i should store the file and
with which extension? Here i'm giving you the code on which i'm working
right now.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
library work;
use work.my_package.all;
entity multiplier1 is
generic (size: integer := 4);
Port ( a,b : in unsigned(size-1 downto 0);
--b : in std_logic;
y : out unsigned(2*size-1 downto 0));
end multiplier1;
architecture Behavioral of multiplier1 is
begin
y <= mult(a,b);
end Behavioral;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
package pack is
function mult(a,b:unsigned) return unsigned;
end pack;
package body pack is
function mult(a,b:unsigned)return unsigned is
constant max:integer := a'length + b'length -1;
variable aa:unsigned(max downto 0) := (max downto a'length => '0') &
a(a'length-1 downto 0);
variable prod:unsigned(max downto 0) := (others => '0');
begin
for i in 0 to a'length-1 loop
if (b(i)='1') then prod:=prod+aa;
end if;
aa := aa(max-1 downto 0) & '0';
end loop;
return prod;
end mult;
end pack;
Regards..
Parthav
I'm not the novice for the VHDL coding but i've not came across adding
the use work.my_package.all in the initial library declaration part.
Now i want help on that what exactly this statement do? Also if i'm
making a function in the package body where i should store the file and
with which extension? Here i'm giving you the code on which i'm working
right now.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
library work;
use work.my_package.all;
entity multiplier1 is
generic (size: integer := 4);
Port ( a,b : in unsigned(size-1 downto 0);
--b : in std_logic;
y : out unsigned(2*size-1 downto 0));
end multiplier1;
architecture Behavioral of multiplier1 is
begin
y <= mult(a,b);
end Behavioral;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
package pack is
function mult(a,b:unsigned) return unsigned;
end pack;
package body pack is
function mult(a,b:unsigned)return unsigned is
constant max:integer := a'length + b'length -1;
variable aa:unsigned(max downto 0) := (max downto a'length => '0') &
a(a'length-1 downto 0);
variable prod:unsigned(max downto 0) := (others => '0');
begin
for i in 0 to a'length-1 loop
if (b(i)='1') then prod:=prod+aa;
end if;
aa := aa(max-1 downto 0) & '0';
end loop;
return prod;
end mult;
end pack;
Regards..
Parthav