playground/vhdl/formal/ripple-ca.vhdl

55 lines
1.2 KiB
VHDL

------------------------
-- Full adder
------------------------
--
-- no (explicit) clock
library ieee;
use ieee.std_logic_1164.all;
entity fa_e is
port (
a, b, cin : in std_logic;
s, cout : out std_logic
);
end entity fa_e;
architecture fa_a of fa_e is
begin
s <= a xor b xor cin;
cout <= (a and b) or (b and cin) or (a and cin);
end architecture fa_a;
---------------------------
-- 4-bit ripple carry adder
---------------------------
library ieee;
use ieee.std_logic_1164.all;
entity rca_e is
port (
a, b : in std_logic_vector(3 downto 0);
cin : in std_logic;
s : out std_logic_vector(3 downto 0);
cout : out std_logic
);
end entity rca_e;
architecture rca_a of rca_e is
-- signals to store intermediate carry values
signal co0, co1, co2 : std_logic;
begin
FA0: entity work.fa_e port map(
a(0), b(0), cin, s(0), co0
-- a(0) => a,
-- b(0) => b,
-- cin => cin,
-- s(0) => s,
-- co0 => cout
);
FA1: entity work.fa_e port map(a(1), b(1), co0, s(1), co1);
FA2: entity work.fa_e port map(a(2), b(2), co1, s(2), co2);
FA3: entity work.fa_e port map(a(3), b(3), co2, s(3), cout);
end architecture rca_a;