Professional Documents
Culture Documents
2 Bit Multiplier
2 Bit Multiplier
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity twobitmultiplier is
Port ( a : in STD_LOGIC_VECTOR (1 downto 0);
b : in STD_LOGIC_VECTOR (1 downto 0);
z : out STD_LOGIC_VECTOR (3 downto 0));
end twobitmultiplier;
signal s1,s2,s3,s4:std_logic;
begin
m1:and1 port map(a(0),b(0),z(0));
m2:and1 port map(a(0),b(1),s1);
m3:and1 port map(a(1),b(0),s2);
end Behavioral;
RTL SCHEMATIC
v<='1';
elsif (a(2)='1') then
b<="010";
v<='1';
elsif (a(1)='1') then
b<="001";
v<='1';
elsif (a(0)='1') then
b<="000";
v<='1';
end if;
end process;
end Behavioral;
RTL SCHEMATIC
4 bit adder/substractor
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity adder is
Port ( a : in STD_LOGIC_VECTOR (3 downto 0);
b : in STD_LOGIC_VECTOR (3 downto 0);
z : out STD_LOGIC_vector (3 downto 0);
cin : in STD_LOGIC;
cout : out STD_LOGIC);
end adder;
architecture Behavioral of adder is
component f_add
Port ( a,b,c : in STD_LOGIC;
z,c0 : out STD_LOGIC);
end component;
component xor1 is
port ( a,b : in STD_LOGIC;
z: out STD_LOGIC);
end component;
signal s1,s2,s3,s4,s5,s6,s7:std_logic;
begin
m1:xor1 port map(b(0),cin,s1);
m2:xor1 port map(b(1),cin,s2);
m3:xor1 port map(b(2),cin,s3);
m4:xor1 port map(b(3),cin,s4);
m5:f_add port map(s1,a(0),cin,z(0),s5);
m6:f_add port map(s2,a(1),s5,z(1),s6);
RTL SCHEMATIC
entity mux16_1 is
Port ( a : in STD_LOGIC_VECTOR (15 downto 0);
o : out STD_LOGIC;
s : in STD_LOGIC_VECTOR (3 downto 0));
end mux16_1;
component m_41
port ( a,b,c,d : in STD_LOGIC;
s1,s2 : in STD_LOGIC;
z : out STD_LOGIC);
end component;
signal s1,s2,s3,s4: std_logic;
begin
m1:m_41 port map (a(0),a(1),a(2),a(3),s(0),s(1),s1);
m2:m_41 port map (a(4),a(5),a(6),a(7),s(0),s(1),s2);
m3:m_41 port map (a(8),a(9),a(10),a(11),s(0),s(1),s3);
m4:m_41 port map (a(12),a(13),a(14),a(15),s(0),s(1),s4);
m5:m_41 port map (s1,s2,s3,s4,s(2),s(3),o);
end Behavioral;
RTL SCHEMATIC
entity m_16_1 is
Port ( a : in STD_LOGIC_VECTOR (15 downto 0);
o : out STD_LOGIC;
s : in STD_LOGIC_VECTOR (3 downto 0));
end m_16_1;
end Behavioral;
RTL SCHEMATIC
2:1 MUX
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity mux_21 is
Port ( a,b,s : in STD_LOGIC;
z : out STD_LOGIC);
end mux_21;
begin
process(a,b,s)
begin
if (s='0') then
z<=a;
else
z<=b;
end if;
end process;
end Behavioral;