www.pudn.com > project_2.zip > real_multiply.vhd, change:2016-01-05,size:2706b


library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;


entity real_multiply is
    Port (clk, en: in std_logic; cin1, cin2: in std_logic_vector(31 downto 0); c_en: out std_logic; cout: out std_logic_vector(31 downto 0));
end real_multiply;

architecture Behavioral of real_multiply is
signal state: std_logic_vector(1 downto 0);
signal tmp1, tmp2: std_logic_vector(23 downto 0);
begin
    p1: process(clk, en)
    variable tmp: std_logic;
    begin
        if(clk'event and clk='1')then
            if(en='1' and tmp/='1')then
                state<="01";
            elsif(state/="00")then
                state<=state+1;
            end if;
            tmp:=en;
        end if;
    end process p1;
    
    p2: process(state)
    variable v1: std_logic_vector(47 downto 0);
    variable v2: std_logic_vector(47 downto 0);
    variable v3: std_logic_vector(8 downto 0);
    variable v4: std_logic_vector(8 downto 0);   
    variable v5: std_logic_vector(8 downto 0);
    begin
        case state is
            when "01"=>
                tmp1(22 downto 0)<=cin1(22 downto 0);
                tmp1(23)<='1';
                tmp2(22 downto 0)<=cin2(22 downto 0);
                tmp2(23)<='1';
                v3(7 downto 0):=cin1(30 downto 23);
                v3(8):='0';
                v4(7 downto 0):=cin2(30 downto 23);
                v4(8):='0';
            when "10"=>
                v2:="000000000000000000000000000000000000000000000000";
                for i in 23 downto 0 loop
                    v1:="000000000000000000000000000000000000000000000000";
                    if(tmp2(i)='1')then
                        v1(23+i downto 0+i):=tmp1;
                    end if;
                    v2:=v2+v1;
                end loop;
                if(v2(47)='0')then
                    cout(22 downto 0)<=v2(45 downto 23);
                else
                    cout(22 downto 0)<=v2(46 downto 24);
                end if;
            when "11"=>
                if(cin1(31)=cin2(31))then
                    cout(31)<='0';
                else
                    cout(31)<='1';
                end if;
                v5:=v3+v4-"001111111"+v2(47);
                if(v5(8)='1' and v3(7)='1' and v4(7)='1')then
                    cout(30 downto 0)<="1111111111111111111111111111111";
                elsif(v5(8)='1' and v3(7)='0' and v4(7)='0')then
                    cout(30 downto 0)<="0000000000000000000000000000000";
                else
                    cout(30 downto 23)<=v5(7 downto 0);
                end if;
                c_en<='1';
            when others=>
                c_en<='0';
            end case;
        end process p2;
end Behavioral;