Lab
Lab
----------------------------------------------------------------------------------
-- Company:
-- Engineer:
--
-- Create Date: 14:45:03 03/16/2023
-- Design Name:
-- Module Name: ha - 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;
entity ha is
Port ( a : in STD_LOGIC;
b : in STD_LOGIC;
s : out STD_LOGIC;
c : out STD_LOGIC);
end ha;
architecture Behavioral of ha is
begin
s<= a XOR b;
c<= a AND b;
end Behavioral;
entity fulladds is
Port ( af : in STD_LOGIC;
bf : in STD_LOGIC;
cin : in STD_LOGIC;
sf : out STD_LOGIC;
cout : out STD_LOGIC);
end fulladds;
end Behavioral;
entity ripple is
Port ( a : in STD_LOGIC_VECTOR (3 downto 0);
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 ripple;
entity addsub is
Port ( a : in STD_LOGIC_VECTOR (3 downto 0);
b : in STD_LOGIC_VECTOR (3 downto 0);
sw : in STD_LOGIC;
s : out STD_LOGIC_VECTOR (3 downto 0);
cout : out STD_LOGIC);
end addsub;
architecture Behavioral of addsub is
component fa1 is
Port ( a : in STD_LOGIC;
b : in STD_LOGIC;
c : in STD_LOGIC;
sum : out STD_LOGIC;
caary : out STD_LOGIC);
end component;
signal sig: STD_LOGIC_VECTOR(3 downto 0);
signal cp: STD_LOGIC_VECTOR(2 downto 0);
begin
sig(0)<=sw XOR b(0);
sig(1)<=sw XOR b(1);
sig(2)<=sw XOR b(2);
sig(3)<=sw XOR b(3);
f1: fa1 port map(a(0),sig(0), sw, s(0), cp(0));
f2: fa1 port map(a(1),sig(1), cp(0), s(1), cp(1));
f3: fa1 port map(a(2),sig(2), cp(1), s(2), cp(2));
f4: fa1 port map(a(3),sig(3), cp(2), s(3), cout);
end Behavioral;