1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
| library ieee; use ieee.std_logic_1164.all;
entity multiplier is port( a: in std_logic_vector(3 downto 0); b: in std_logic_vector(3 downto 0); result: out std_logic_vector(7 downto 0) ); end multiplier;
architecture behavioral of multiplier is
component adder4multiplier is port( x: in std_logic_vector(3 downto 0); y: in std_logic_vector(3 downto 0); sel: in std_logic; s: out std_logic_vector(3 downto 0); co: out std_logic ); end component;
component adder4multiplier is port( bin :in std_logic_vector (7 downto 0); bcd0 : out std_logic_vector (3 downto 0); bcd1 : out std_logic_vector (3 downto 0); bcd2 : out std_logic_vector (3 downto 0) ); end component;
signal anb0, anb1, anb2, anb3: std_logic_vector(3 downto 0); signal y_4_adder0, y_4_adder1, y_4_adder2: std_logic_vector(3 downto 0); signal sum0, sum1, sum2: std_logic_vector(3 downto 0); signal carry0, carry1, carry2: std_logic;
begin a_and_b: process(a, b) begin for i in 0 to 3 loop anb0(i) <= b(0) and a(i); anb1(i) <= b(1) and a(i); anb2(i) <= b(2) and a(i); anb3(i) <= b(3) and a(i); end loop; end process;
data_4_adder0: process(anb0) begin for i in 0 to 2 loop y_4_adder0(i) <= anb0(i+1); end loop; end process; y_4_adder0(3) <= '0';
adder_0: adder4multiplier port map( x => anb1, y => y_4_adder0, sel => '0', s => sum0, co => carry0 );
data_4_adder1: process(sum0) begin for i in 0 to 2 loop y_4_adder1(i) <= sum0(i+1); end loop; end process;
y_4_adder1(3) <= carry0;
adder_1: adder4multiplier port map( x => anb2, y => y_4_adder1, sel => '0', s => sum1, co => carry1 ); data_4_adder2: process(sum1) begin for i in 0 to 2 loop y_4_adder2(i) <= sum1(i+1); end loop; end process;
y_4_adder2(3) <= carry1;
adder_2: adder4multiplier port map( x => anb3, y => y_4_adder2, sel => '0', s => sum2, co => carry2 );
result(0) <= anb0(0); result(1) <= sum0(0); result(2) <= sum1(0);
z3_to_z6: process(sum2) begin for i in 0 to 3 loop result(i+3) <= sum2(i); end loop; end process;
result(7) <= carry2;
end behavioral;
|