phobos1
Full Member level 2
- Joined
- Jan 18, 2010
- Messages
- 135
- Helped
- 15
- Reputation
- 30
- Reaction score
- 15
- Trophy points
- 1,298
- Location
- Salem, Tamil Nadu, India
- Activity points
- 2,112
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Value 0 is out of range 3 to 0 (null range).
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity multiplier is
port(mul1,mul2:in std_logic_vector(3 downto 0);
produt std_logic_vector(7 downto 0));
end multiplier;
architecture arch_multiplier of multiplier is
component adder is
port(a_4,b_4: in std_logic_vector(7 downto 0);
s_4: out std_logic_vector(7 downto 0));
end component;
type arraytype is array(3 to 0) of std_logic_vector(7 downto 0);
--type arraytype1 is array(3 to 0) of std_logic_vector(8 downto 0);
signal temp:arraytype;
signal temp_prod:arraytype;
begin
process(mul1,mul2)
variable temp_mul1:std_logic_vector(15 downto 0):="0000000000000000";
begin
temp_mul1(0):=(mul1(0) and mul2(0));
temp_mul1(1):=(mul1(1) and mul2(0));
temp_mul1(2):=(mul1(2) and mul2(0));
temp_mul1(3):=(mul1(3) and mul2(0));
temp_mul1(4):=(mul1(0) and mul2(1));
temp_mul1(5):=(mul1(1) and mul2(1));
temp_mul1(6):=(mul1(2) and mul2(1));
temp_mul1(7):=(mul1(3) and mul2(1));
temp_mul1(8):=(mul1(0) and mul2(2));
temp_mul1(9):=(mul1(1) and mul2(2));
temp_mul1(10):=(mul1(2) and mul2(2));
temp_mul1(11):=(mul1(3) and mul2(2));
temp_mul1(12):=(mul1(0) and mul2(3));
temp_mul1(13):=(mul1(1) and mul2(3));
temp_mul1(14):=(mul1(2) and mul2(3));
temp_mul1(15):=(mul1(3) and mul2(3));
temp(0)<="0000"&temp_mul1(3)&temp_mul1(2)&temp_mul1(1)&temp_mul1(0);
temp(1)<="000"&temp_mul1(7)&temp_mul1(6)&temp_mul1(5)&temp_mul1(4)&'0';
temp(2)<="00"&temp_mul1(11)&temp_mul1(10)&temp_mul1(9)&temp_mul1(8)&"00";
temp(3)<='0'&temp_mul1(15)&temp_mul1(14)&temp_mul1(13)&temp_mul1(12)&"000";
ad1:adder port map(a_4=>temp(0),b_4=>temp(1),s_4=>temp_prod(0));
ad2:adder port map(a_4=>temp_prod(0),b_4=>temp(2),s_4=>temp_prod(1));
ad3:adder port map(a_4=>temp_prod(1),b_4=>temp(3),s_4=>temp_prod(2));
prod<=temp_prod(2);
end process;
end arch_multiplier;
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity multiplier is
port(mul1,mul2:in std_logic_vector(3 downto 0);
produt std_logic_vector(7 downto 0));
end multiplier;
architecture arch_multiplier of multiplier is
component adder is
port(a_4,b_4: in std_logic_vector(7 downto 0);
s_4: out std_logic_vector(7 downto 0));
end component;
type arraytype is array(3 to 0) of std_logic_vector(7 downto 0);
--type arraytype1 is array(3 to 0) of std_logic_vector(8 downto 0);
signal temp:arraytype;
signal temp_prod:arraytype;
begin
process(mul1,mul2)
variable temp_mul1:std_logic_vector(15 downto 0):="0000000000000000";
begin
temp_mul1(0):=(mul1(0) and mul2(0));
temp_mul1(1):=(mul1(1) and mul2(0));
temp_mul1(2):=(mul1(2) and mul2(0));
temp_mul1(3):=(mul1(3) and mul2(0));
temp_mul1(4):=(mul1(0) and mul2(1));
temp_mul1(5):=(mul1(1) and mul2(1));
temp_mul1(6):=(mul1(2) and mul2(1));
temp_mul1(7):=(mul1(3) and mul2(1));
temp_mul1(8):=(mul1(0) and mul2(2));
temp_mul1(9):=(mul1(1) and mul2(2));
temp_mul1(10):=(mul1(2) and mul2(2));
temp_mul1(11):=(mul1(3) and mul2(2));
temp_mul1(12):=(mul1(0) and mul2(3));
temp_mul1(13):=(mul1(1) and mul2(3));
temp_mul1(14):=(mul1(2) and mul2(3));
temp_mul1(15):=(mul1(3) and mul2(3));
temp(0)<="0000"&temp_mul1(3)&temp_mul1(2)&temp_mul1(1)&temp_mul1(0);
temp(1)<="000"&temp_mul1(7)&temp_mul1(6)&temp_mul1(5)&temp_mul1(4)&'0';
temp(2)<="00"&temp_mul1(11)&temp_mul1(10)&temp_mul1(9)&temp_mul1(8)&"00";
temp(3)<='0'&temp_mul1(15)&temp_mul1(14)&temp_mul1(13)&temp_mul1(12)&"000";
ad1:adder port map(a_4=>temp(0),b_4=>temp(1),s_4=>temp_prod(0));
ad2:adder port map(a_4=>temp_prod(0),b_4=>temp(2),s_4=>temp_prod(1));
ad3:adder port map(a_4=>temp_prod(1),b_4=>temp(3),s_4=>temp_prod(2));
prod<=temp_prod(2);
end process;
end arch_multiplier;