30 June 2010

8-bit Conditional Sum Adder (CSA8)

Logic gate for an 8-bit Conditional Sum Adder (CSA8). Here carry_in (C_in) and carry_out (C_out) are used (in the eventuality of a 16-bit extension).


It has three inputs: 1-bit C_in (carry_in - not used in the VHDL code!), 8-bit X[7..0] and 8-bit Y[7..0]. It uses three 4-bit Conditional Sum Adder (CSA4) blocks and one 10 to 5 Multiplexer (10to5MUX) block. It has two outputs: 8-bit S[7..0] and C_out (carry_out - not used in the VHDL code!).



VHDL code for the 8-bit Conditional Sum Adder (CSA8):

-- 8-bit Conditional Sum Adder (CSA8)
-- inputs: X[7..0], Y[7..0]
-- outputs: S[7..0]
-- carry_in and carry_out not used!!! (do not intend to extend on 16-bit!)

LIBRARY ieee;
USE ieee.std_logic_1164.all;

entity CSA8 is
    PORT (X, Y: in bit_vector(7 downto 0);
          S: out bit_vector(7 downto 0));
end CSA8;

architecture logic of CSA8 is

    component CSA4 is
        PORT( C_in: in bit;
              X, Y: in bit_vector(3 downto 0);
              S: out bit_vector(3 downto 0);
              C_out: out bit);
    end component;
   
    component MUX10_5 is
        PORT( sel: in bit;
              X, Y: in bit_vector(4 downto 0);
              m: out bit_vector(4 downto 0));
    end component;
   
    constant c: bit := '1';
    signal msel: bit;
    signal mx, my: bit_vector(4 downto 0);
   
   
begin
    csa4_inst0 : CSA4
    PORT MAP( C_in => '0', X => X(3 downto 0), Y => Y(3 downto 0),
              S => S(3 downto 0), C_out => msel);
             
    csa4_inst1 : CSA4
    PORT MAP( C_in => c, X => X(7 downto 4), Y => Y(7 downto 4),
              S => mx(3 downto 0), C_out => mx(4));
             
    csa4_inst2 : CSA4
    PORT MAP( C_in => not c, X => X(7 downto 4), Y => Y(7 downto 4),
              S => my(3 downto 0), C_out => my(4));
             
    mux10_5_inst0 : MUX10_5
    PORT MAP( sel => msel, X => mx, Y => my,
              m(3 downto 0) => S(7 downto 4));         
end logic;

10 to 5 Multiplexer

Logic gate for a 10 to 5 Multiplexer (10to5MUX):


It has three inputs: 1-bit sel (selector), 5-bit X[4..0] and 5-bit Y[4..0]. It uses a 6 to 3 Multiplexer block (6to3MUX) and a 4 to 2 Multiplexer block (4to2MUX). It has a 5-bit output m[4..0].


VHDL code for the 10 to 5 Multiplexer:


-- 10 to 5 Multiplexer
-- inputs: 1-bit sel (selector), 5-bit X, 5-bit Y
-- outputs: 5-bit m

LIBRARY ieee;
USE ieee.std_logic_1164.all;


entity MUX10_5 is
    PORT( sel: in bit;
          X, Y: in bit_vector(4 downto 0);
          m: out bit_vector(4 downto 0));
end MUX10_5;

architecture logic of MUX10_5 is

    component MUX6_3 is
        PORT( sel: in bit;
              X, Y: in bit_vector(2 downto 0);
              m: out bit_vector(2 downto 0));
    end component;
   
    component MUX4_2 is
        PORT( sel, X0, X1, Y0, Y1: in bit;
              m0, m1: out bit);
    end component;
   
begin

    mux6_3_inst0 : MUX6_3
    PORT MAP( sel => sel, X => X(2 downto 0), Y => Y(2 downto 0),
              m => m(2 downto 0));
             
    mux4_2_inst0 : MUX4_2
    PORT MAP( sel => sel, X0 => X(3), X1 => X(4), Y0 => Y(3), Y1 => Y(4),
              m0 => m(3), m1 => m(4));
             
end logic;

8 to 4 Multiplexer

Logic gate for an 8 to 4 Multiplexer (8to4MUX):


It has 3 inputs: 1-bit sel (selector), 4-bit X[3..0] and 4-bit Y[3..0]. It uses two 4to2 Multiplexer blocks (4to2MUX). It has one 4-bit output m[3..0].


VHDL code for the 8to4 Multiplexer:

-- 8 to 4 Multiplexer
-- inputs: 1-bit sel (selector), 4-bit X, 4-bit Y
-- outputs: 4-bit m

LIBRARY ieee;
USE ieee.std_logic_1164.all;

entity MUX8_4 is
    PORT( sel: in bit;
          X, Y: in bit_vector(3 downto 0);
          m: out bit_vector(3 downto 0));
end MUX8_4;


architecture logic of MUX8_4 is

    component MUX4_2 is
        PORT( sel, X0, X1, Y0, Y1: in bit;
              m0, m1: out bit);
    end component;
   
begin
    mux4_2_inst0 : MUX4_2
    PORT MAP( sel => sel, X0 => X(0), X1 => X(1), Y0 => Y(0), Y1 => Y(1),
              m0 => m(0), m1 => m(1));
             
    mux4_2_inst1 : MUX4_2
    PORT MAP( sel => sel, X0 => X(2), X1 => X(3), Y0 => Y(2), Y1 => Y(3),
              m0 => m(2), m1 => m(3));        
end logic;

29 June 2010

4-bit Conditional Sum Adder (CSA4)

Logic gate for a 4 bit Conditional Sum Adder (CSA4):


It uses three inputs:  one 1-bit C_in (carry in) and two 4-bit summands X[3..0], Y[3..0]. It makes use of three 2-bit Conditional Sum Adder blocks (CSA2) and a 6 to 3 Multiplexer (6to3MUX). It has two outputs: 4-bit S[3..0] and a 1-bit C_out (carry out).


VHDL code for a 4-bit Conditional Sum Adder (CSA4):


-- 4-bit Conditional Sum Adder (CSA4)
-- inputs: C_in (carry in), X[3..0], Y[3..0]
-- outputs: S[3..0], C_out (carry out)

LIBRARY ieee;
USE ieee.std_logic_1164.all;


entity CSA4 is
    PORT( C_in: in bit;
          X, Y: in bit_vector(3 downto 0);
          S: out bit_vector(3 downto 0);
          C_out: out bit);
end CSA4;


architecture logic of CSA4 is

    component CSA2 is
        PORT( C_in: in bit;
              X, Y: in bit_vector(1 downto 0);
              S: out bit_vector(1 downto 0);
              C_out: out bit);
    end component;
   
    component MUX6_3 is
        PORT( sel: in bit;
              X, Y: in bit_vector(2 downto 0);
              m: out bit_vector(2 downto 0));
    end component;
   
    constant c: bit :='1';
    signal m_sel: bit;
    signal mx, my: bit_vector(2 downto 0);
    signal st: bit_vector(2 downto 0);
   
   
begin

    csa2_inst0 : CSA2
    PORT MAP(C_in => C_in, X => X(1 downto 0), Y => Y(1 downto 0),
             S => S(1 downto 0), C_out => m_sel);
             
    csa2_inst1 : CSA2
    PORT MAP(C_in => c, X => X(3 downto 2), Y => Y(3 downto 2),
             S => mx(1 downto 0), C_out => mx(2));
             
    csa2_inst2 : CSA2
    PORT MAP(C_in => not c, X => X(3 downto 2), Y => Y(3 downto 2),
             S => my(1 downto 0), C_out => my(2));
             
    mux6_3_inst0 : MUX6_3
    PORT MAP(sel => m_sel, X => mx, Y => my,
             m => st);
             
    S(3 downto 2) <= st(1 downto 0);
    C_out <= st(2);
   
end logic;

6 to 3 Multiplexer

Logic gate for a 6 to 3 Multiplexer:


It uses three inputs: one 1-bit sel (selector), 3-bit X (X0, X1, X2) and 3-bit Y (Y0, Y1, Y2), it also uses a 4to2 multiplexer (MUX4_2), two AND gates and one OR gate. It has a 3-bit output m.


VHDL code for the 6 to 3 Multiplexer:

-- 6 to 3 Multiplexer
-- inputs: 1bit sel, 3bit X, 3bitY
-- outputs: 3bit m

LIBRARY ieee;
USE ieee.std_logic_1164.all;


entity MUX6_3 is
    PORT( sel: IN bit
          X, Y: IN bit_vector(2 downto 0);
          m: OUT bit_vector(2 downto 0));
end MUX6_3;


architecture logic of MUX6_3 is

    component MUX4_2 is
        PORT( sel, X0, X1, Y0, Y1: in bit;
              m0, m1: out bit);
    end component;
   
begin
    mux4_2_inst0 : MUX4_2
    PORT MAP( sel => sel, X0 => X(0), X1 => X(1), Y0 => Y(0), Y1 => Y(1),
              m0 => m(0), m1 => m(1));
             
    m(2) <= (X(2) and sel) or (Y(2) and not sel);
end logic;