用booth算法求[x*y]补。x=0.1101,y=-0.1010

如题所述

第1个回答  2008-05-22
首先编程把原码变为补码,这个资料很多,可以查看
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位乘法器,你可以稍作修改本回答被提问者采纳