Ripple Carry Chain Adder - VHDL

-- (C) David Vajda
-- Ripple Carry Chain Adder / Subtrahierer / Volladdierer
-- 2024-11-28

library ieee;
use ieee.std_logic_1164.all;

entity fulladder20241128 is
port (
    a: in std_logic;
    b: in std_logic;
    c: out std_logic;
    s: in std_logic;
    t: out std_logic
);
end;

architecture behaviour of fulladder20241128 is
begin
    c <= a xor b xor s;
    t <= (a and b) or ((a or b) and s);
end;

library ieee;
use ieee.std_logic_1164.all;

entity ripplecarrychainadder20241128 is
port (
    a3, a2, a1, a0: in std_logic;
    b3, b2, b1, b0: in std_logic;
    c3, c2, c1, c0: out std_logic;
    s: in std_logic;
    t: out std_logic
);
end;

architecture behaviour of ripplecarrychainadder20241128 is
    component fulladder20241128
    port (
        a: in std_logic;
        b: in std_logic;
        c: out std_logic;
        s: in std_logic;
        t: out std_logic
    );
    end component;
    signal s3, s2, s1, s0: std_logic;
begin
    fa3: fulladder20241128 PORT MAP (a=>a3, b=>b3, c=>c3, s=>s3, t=>t);
    fa2: fulladder20241128 PORT MAP (a=>a2, b=>b2, c=>c2, s=>s2, t=>s3);
    fa1: fulladder20241128 PORT MAP (a=>a1, b=>b1, c=>c1, s=>s1, t=>s2);
    fa0: fulladder20241128 PORT MAP (a=>a0, b=>b0, c=>c0, s=>s, t=>s1);
end;

library ieee;
use ieee.std_logic_1164.all;

entity ripplecarrychainadder20241128testbench is
port (
    c3, c2, c1, c0: out std_logic;
    t: out std_logic
);
end;

architecture behaviour of ripplecarrychainadder20241128testbench is
    component ripplecarrychainadder20241128
    port (
        a3, a2, a1, a0: in std_logic;
        b3, b2, b1, b0: in std_logic;
        c3, c2, c1, c0: out std_logic;
        s: in std_logic;
        t: out std_logic
    );
    end component;
    signal a3, a2, a1, a0: std_logic;
    signal b3, b2, b1, b0: std_logic;
    signal s: std_logic;
begin
    rfa: ripplecarrychainadder20241128 PORT MAP (a3=>a3, a2=>a2, a1=>a1, a0=>a0, b3=>b3, b2=>b2, b1=>b1, b0=>b0, c3=>c3, c2=>c2, c1=>c1, c0=>c0, s=>s, t=>t);

    a3 <= '0' after 0 ns, '0' after 10 ns;
    a2 <= '1' after 0 ns, '0' after 10 ns;
    a1 <= '0' after 0 ns, '0' after 10 ns;
    a0 <= '1' after 0 ns, '0' after 10 ns;
    b3 <= '0' after 0 ns, '0' after 10 ns;
    b2 <= '0' after 0 ns, '0' after 10 ns;
    b1 <= '1' after 0 ns, '0' after 10 ns;
    b0 <= '1' after 0 ns, '0' after 10 ns;
    s <= '0' after 0 ns, '1' after 10 ns;
end;

Image Screenshot_20241128_093000