booth乘法的源碼是:
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 : in std_logic_vector(7 downto 0);
bi : in std_logic_vector(7 downto 0)
done : out std_logic;
clk : in std_logic;
op : out std_logic_vector(15 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位乘法器,妳可以稍作修改