基于booth算法的有符號數乘法VHDL源代碼,這是8位二進制乘法的,關于十進制轉2進制的程序很簡單,可以自己設置下,乘法器部分如下:library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; ---- Uncomment the following library declaration if instantiating ---- any Xilinx primitives in this code. --library UNISIM; --use UNISIM.VComponents.all; entity mp is Port ( ai,bi : in std_logic_vector(7 downto 0); done : out std_logic; clk : in std_logic; op : out std_logic_vector(7 downto 0)); end mp; architecture Behavioral of mp is begin process(ai,bi,clk) variable a,b,m : std_logic_vector( 7 downto 0); variable cp: std_logic_vector( 1 downto 0); variable t: std_logic ; variable counter: integer; begin if clk'event and clk='1' then counter:=0; t:='0'; a:=ai; b:=bi; m:="00000000"; cp:=b(0)&'0'; done<='0'; --是否完成計算 while counter<8 loop case cp is when "10"=> m:=m-a; when "01"=> m:=m+a; when others=>m:=m; end case; t:=b(0); b:=m(0)&b(7 downto 1); m:=m(7)&m(7 downto 1); cp:=b(0)&t; counter:=counter+1; end loop; op<= m&b; done<='1'; end if; end process; end Behavioral; 然后下面這個是加法器樹乘法器的源代碼,也是8位2進制乘法源碼,如果這兩種方法還不夠就MMM我好了library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity ywxj_multipier isport(clk: in std_logic; a: in std_logic_vector(7 downto 0);--乘數 b: in std_logic_vector(7 downto 0);--被乘數 y: out std_logic_vector(15 downto 0));--輸出end ywxj_multipier;architecture rtl of ywxj_multipier isbeginp1: process(clk) variable n0,n1,n2,n3,n4,n5,n6,n7: std_logic_vector(15 downto 0); variable m: std_logic_vector(7 downto 0); begin m:="00000000"; if clk'event and clk='1' then if a(0)<='0' then n0:="0000000000000000"; else n0:=m&b; end if; if a(1)<='0' then n1:="0000000000000000"; else n1:=m(7 downto 1)&b&m(0); end if; if a(2)<='0' then n2:="0000000000000000"; else n2:=m(7 downto 2)&b&m(1 downto 0); end if; if a(3)<='0' then n3:="0000000000000000"; else n3:=m(7 downto 3)&b&m(2 downto 0); end if; if a(4)<='0' then n4:="0000000000000000"; else n4:=m(7 downto 4)&b&m(3 downto 0); end if; if a(5)<='0' then n5:="0000000000000000"; else n5:=m(7 downto 5)&b&m(4 downto 0); end if; if a(6)<='0' then n6:="0000000000000000"; else n6:=m(7 downto 6)&b&m(5 downto 0); end if; if a(7)<='0' then n7:="0000000000000000"; else n7:=m(7)&b&m(6 downto 0); end if; y<=n0+n1+n2+n3+n4+n5+n6+n7; end if; end process p1;end rtl;
|