----------------------------------------------------------------------------------
-- Company: 
-- Engineer: 
-- 
-- Create Date: 30.11.2023 12:57:31
-- Design Name: 
-- Module Name: braunsmultiplier - Behavioral
-- Project Name: 
-- Target Devices: 
-- Tool Versions: 
-- Description: 
-- 
-- Dependencies: 
-- 
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
-- 
----------------------------------------------------------------------------------


library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.std_logic_arith.ALL;
use IEEE.std_logic_unsigned.ALL;

-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--use IEEE.NUMERIC_STD.ALL;

-- Uncomment the following library declaration if instantiating
-- any Xilinx leaf cells in this code.
--library UNISIM;
--use UNISIM.VComponents.all;

entity brauns_multiplier is
    Port ( A : in STD_LOGIC_vector(7 downto 0);
           B : in STD_LOGIC_vector(7 downto 0);
           P : out STD_LOGIC_vector(15 downto 0));
           
end brauns_multiplier;

architecture Behavioral of brauns_multiplier is

signal A1B0 : std_logic;
Signal A2B0 : std_logic;
Signal A3B0 : std_logic;
Signal A4B0 : std_logic;
Signal A5B0 : std_logic;
Signal A6B0 : std_logic;
Signal A7B0 : std_logic;

Signal A0B1 : std_logic;
Signal A1B1 : std_logic;
Signal A2B1 : std_logic;
Signal A3B1 : std_logic;
Signal A4B1 : std_logic;
Signal A5B1 : std_logic;
Signal A6B1 : std_logic;
Signal A7B1 : std_logic;

Signal A0B2 : std_logic;
Signal A1B2 : std_logic;
Signal A2B2 : std_logic;
Signal A3B2 : std_logic;
Signal A4B2 : std_logic;
Signal A5B2 : std_logic;
Signal A6B2 : std_logic;
Signal A7B2 : std_logic;

Signal A0B3 : std_logic;
Signal A1B3 : std_logic;
Signal A2B3 : std_logic;
Signal A3B3 : std_logic;
Signal A4B3 : std_logic;
Signal A5B3 : std_logic;
Signal A6B3 : std_logic;
Signal A7B3 : std_logic;

Signal A0B4 : std_logic;
Signal A1B4 : std_logic;
Signal A2B4 : std_logic;
Signal A3B4 : std_logic;
Signal A4B4 : std_logic;
Signal A5B4 : std_logic;
Signal A6B4 : std_logic;
Signal A7B4 : std_logic;

Signal A0B5 : std_logic;
Signal A1B5 : std_logic;
Signal A2B5 : std_logic;
Signal A3B5 : std_logic;
Signal A4B5 : std_logic;
Signal A5B5 : std_logic;
Signal A6B5 : std_logic;
Signal A7B5 : std_logic;

Signal A0B6 : std_logic;
Signal A1B6 : std_logic;
Signal A2B6 : std_logic;
Signal A3B6 : std_logic;
Signal A4B6 : std_logic;
Signal A5B6 : std_logic;
Signal A6B6 : std_logic;
Signal A7B6 : std_logic;

Signal A0B7 : std_logic;
Signal A1B7 : std_logic;
Signal A2B7 : std_logic;
Signal A3B7 : std_logic;
Signal A4B7 : std_logic;
Signal A5B7 : std_logic;
Signal A6B7 : std_logic;
Signal A7B7 : std_logic;

Signal S1,S2,S3,S4,S5,S6,S7,S8,S10,S11,S12,S13,S14,S15,S16,S18,S19,S20,S21,S22,S23,S24,S26,S27,S28,S29,S30,S31,S32,S34,S35,S36,S37,S38,S39,S40,S42,S43,S44,S45,S46,S47,S48 : std_logic;
Signal C1,C2,C3,C4,C5,C6,C7,C8,C9,C10,C11,C12,C13,C14,C15,C16,C17,C18,C19,C20,C21,C22,C23,C24,C25,C26,C27,C28,C29,C30,C31,C32,C33,C34,C35,C36,C37,C38,C39,C40,C41,C42,C43,C44,C45,C46,C47,C48,C49,C50,C51,C52,C53,C54,C55,C56 : std_logic;

component Fulladder is
Port ( A : in std_logic;
       B : in std_logic;
       Cin : in std_logic;
       Sum : out std_logic;
       Cout : out std_logic);
end component;

Component halfadder is
Port ( A : in std_logic;
       B : in std_logic;
       Sum : out std_logic;
       Cout : out std_logic);    
end component; 

begin

A1B0 <= A(1) and B(0);
A2B0 <= A(2) and B(0);
A3B0 <= A(3) and B(0);
A4B0 <= A(4) and B(0);
A5B0 <= A(5) and B(0);
A6B0 <= A(6) and B(0);
A7B0 <= A(7) and B(0);

A0B1 <= A(0) and B(1);
A1B1 <= A(1) and B(1);
A2B1 <= A(2) and B(1);
A3B1 <= A(3) and B(1);
A4B1 <= A(4) and B(1);
A5B1 <= A(5) and B(1);
A6B1 <= A(6) and B(1);
A7B1 <= A(7) and B(1);

A0B2 <= A(0) and B(2);
A1B2 <= A(1) and B(2);
A2B2 <= A(2) and B(2);
A3B2 <= A(3) and B(2);
A4B2 <= A(4) and B(2);
A5B2 <= A(5) and B(2);
A6B2 <= A(6) and B(2);
A7B2 <= A(7) and B(2);

A0B3 <= A(0) and B(3);
A1B3 <= A(1) and B(3);
A2B3 <= A(2) and B(3);
A3B3 <= A(3) and B(3);
A4B3 <= A(4) and B(3);
A5B3 <= A(5) and B(3);
A6B3 <= A(6) and B(3);
A7B3 <= A(7) and B(3);

A0B4 <= A(0) and B(4);
A1B4 <= A(1) and B(4);
A2B4 <= A(2) and B(4);
A3B4 <= A(3) and B(4);
A4B4 <= A(4) and B(4);
A5B4 <= A(5) and B(4);
A6B4 <= A(6) and B(4);
A7B4 <= A(7) and B(4);

A0B5 <= A(0) and B(5);
A1B5 <= A(1) and B(5);
A2B5 <= A(2) and B(5);
A3B5 <= A(3) and B(5);
A4B5 <= A(4) and B(5);
A5B5 <= A(5) and B(5);
A6B5 <= A(6) and B(5);
A7B5 <= A(7) and B(5);

A0B6 <= A(0) and B(6);
A1B6 <= A(1) and B(6);
A2B6 <= A(2) and B(6);
A3B6 <= A(3) and B(6);
A4B6 <= A(4) and B(6);
A5B6 <= A(5) and B(6);
A6B6 <= A(6) and B(6);
A7B6 <= A(7) and B(6);

A0B7 <= A(0) and B(7);
A1B7 <= A(1) and B(7);
A2B7 <= A(2) and B(7);
A3B7 <= A(3) and B(7);
A4B7 <= A(4) and B(7);
A5B7 <= A(5) and B(7);
A6B7 <= A(6) and B(7);
A7B7 <= A(7) and B(7);

-- Stage 1
P0 : P(0) <= A (0) and B (0) ;

P1 : halfadder port map (A=>A1B0, B=>A0B1, Sum=>P(1), Cout=>C1);

S2_1 : fulladder port map (A=>A2B0, B=>A1B1, Cin=>C1, Sum=>S2, Cout=>C2);
P2 : halfadder port map (A=>A0B2, B=>S2, Sum=>P(2), Cout=>C9);

S3_1 : fulladder port map (A=>A3B0, B=>A2B1,Cin=>C2, Sum=>S3, Cout=>C3);
S10_1 : fulladder port map (A=>A1B2, B=>S3, Cin=>C9, Sum=>S10, Cout=>C10);
P3 : halfadder port map (A=>A0B3, B=>S10, Sum=>P(3), Cout=>C17);

S4_1 : fulladder port map (A=>A4B0, B=>A3B1, Cin=>C3, Sum=>S4, Cout=>C4);
S11_1: fulladder port map (A=>A2B2, B=>S4, Cin=>C10, Sum=>S11, Cout=>C11);
S18_1: fulladder port map (A=>A1B3, B=>S11, Cin=>C17, Sum=>S18, Cout=>C18);
P4: halfadder port map (A=>A0B4, B=>S18, Sum=>P(4), Cout=>C25);

S5_1: fulladder port map (A=>A5B0, B=>A4B1, Cin=>C4, Sum=>S5, Cout=>C5);
S12_1: fulladder port map (A=>A3B2, B=>S5, Cin=>C11, Sum=>S12, Cout=>C12);
S19_1: fulladder port map (A=>A2B3, B=>S12, Cin=>C18, Sum=>S19, Cout=>C19);
S26_1: fulladder port map (A=>A1B4, B=>S19, Cin=>C25, Sum=>S26, Cout=>C26);
P5: halfadder port map (A=>A0B5, B=>S26, Sum=>P(5), Cout=>C33);

S6_1: fulladder port map (A=>A6B0, B=>A5B1, Cin=>C5, Sum=>S6, Cout=>C6);
S13_1: fulladder port map (A=>A4B2, B=>S6, Cin=>C12, Sum=>S13, Cout=>C13);
S20_1: fulladder port map (A=>A3B3, B=>S13, Cin=>C19, Sum=>S20, Cout=>C20);
S27_1: fulladder port map (A=>A2B4, B=>S20, Cin=>C26, Sum=>S27, Cout=>C27);
S34_1: fulladder port map (A=>A1B5, B=>S27, Cin=>C33, Sum=>S34, Cout=>C34);
P6: halfadder port map (A=>A0B6, B=>S34, Sum=>P(6), Cout=>C41);

S7_1: fulladder port map (A=>A7B0, B=>A6B1, Cin=>C6, Sum=>S7, Cout=>C7);
S14_1: fulladder port map (A=>A5B2, B=>S7, Cin=>C13, Sum=>S14, Cout=>C14);
S21_1: fulladder port map (A=>A4B3, B=>S14, Cin=>C20, Sum=>S21, Cout=>C21);
S28_1: fulladder port map (A=>A3B4, B=>S21, Cin=>C27, Sum=>S28, Cout=>C28);
S35_1: fulladder port map (A=>A2B5, B=>S28, Cin=>C34, Sum=>S35, Cout=>C35);
S42_1: fulladder port map (A=>A1B6, B=>S35, Cin=>C41, Sum=>S42, Cout=>C42);
P7: halfadder port map (A=>A0B7, B=>S42, Sum=>P(7), Cout=>C49);

S8_1: halfadder port map (A=>A7B1, B=>C7, Sum=>S8, Cout=>C8);
S15_1: fulladder port map (A=>A6B2, B=>S8, Cin=>C14, Sum=>S15, Cout=>C15);
S22_1: fulladder port map (A=>A5B3, B=>S15, Cin=>C21, Sum=>S22, Cout=>C22);
S29_1: fulladder port map (A=>A4B4, B=>S22, Cin=>C28, Sum=>S29, Cout=>C29);
S36_1: fulladder port map (A=>A3B5, B=>S29, Cin=>C35, Sum=>S36, Cout=>C36);
S43_1: fulladder port map (A=>A2B6, B=>S36, Cin=>C42, Sum=>S43, Cout=>C43);
P8: fulladder port map (A=>A1B7, B=>S43, Cin=>C49, Sum=>P(8), Cout=>C50);

S16_1: fulladder port map (A=>A7B2, B=>C8, Cin=>C15, Sum=>S16, Cout=>C16);
S23_1: fulladder port map (A=>A6B3, B=>S16, Cin=>C22, Sum=>S23, Cout=>C23);
S30_1: fulladder port map (A=>A5B4, B=>S23, Cin=>C29, Sum=>S30, Cout=>C30);
S37_1: fulladder port map (A=>A4B5, B=>S30, Cin=>C36, Sum=>S37, Cout=>C37);
S44_1: fulladder port map (A=>A3B6, B=>S37, Cin=>C43, Sum=>S44, Cout=>C44);
P9: fulladder port map (A=>A2B7, B=>S44, Cin=>C50, Sum=>P(9), Cout=>C51);

S24_1: fulladder port map (A=>A7B3, B=>C16, Cin=>C23, Sum=>S24, Cout=>C24);
S31_1: fulladder port map (A=>A6B4, B=>S24, Cin=>C30, Sum=>S31, Cout=>C31);
S38_1: fulladder port map (A=>A5B5, B=>S31, Cin=>C37, Sum=>S38, Cout=>C38);
S45_1: fulladder port map (A=>A4B6, B=>S38, Cin=>C44, Sum=>S45, Cout=>C45);
P10: fulladder port map (A=>A3B7, B=>S45, Cin=>C51, Sum=>P(10), Cout=>C52);

S32_1: fulladder port map (A=>A7B4, B=>C24, Cin=>C31, Sum=>S32, Cout=>C32);
S39_1: fulladder port map (A=>A6B5, B=>S32, Cin=>C38, Sum=>S39, Cout=>C39);
S46_1: fulladder port map (A=>A5B6, B=>S39, Cin=>C45, Sum=>S46, Cout=>C46);
P11: fulladder port map (A=>A4B7, B=>S46, Cin=>C52, Sum=>P(11), Cout=>C53);

S40_1: fulladder port map (A=>A7B5, B=>C32, Cin=>C39, Sum=>S40, Cout=>C40);
S47_1: fulladder port map (A=>A6B6, B=>S40, Cin=>C46, Sum=>S47, Cout=>C47);
P12: fulladder port map (A=>A5B7, B=>S47, Cin=>C53, Sum=>P(12), Cout=>C54);

S48_1: fulladder port map (A=>A7B6, B=>C40, Cin=>C47, Sum=>S48, Cout=>C48);
P13: fulladder port map (A=>A6B7, B=>S48, Cin=>C54, Sum=>P(13), Cout=>C55);

P14: fulladder port map (A=>A7B7, B=>C48, Cin=>C55, Sum=>P(14), Cout=>C56);

P15: P(15) <= C56;

end Behavioral;
