當前位置:編程學習大全網 - 源碼下載 - 用booth算法求[x*y]補。x=0.1101,y=-0.1010

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

首先編程把原碼變為補碼,這個資料很多,可以查看

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位乘法器,妳可以稍作修改

  • 上一篇:知識付費源代碼查詢
  • 下一篇:java過濾sql關鍵字的正則替換掉
  • copyright 2024編程學習大全網