VHDL code
VHDL code
entity MUX4to1 is
Port (
A, B, C, D : in STD_LOGIC; -- Inputs
S : in STD_LOGIC_VECTOR (1 downto 0); -- Select lines
Y : out STD_LOGIC -- Output
);
end MUX4to1;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity BasicGates is
Port (
A, B : in STD_LOGIC; -- Inputs
AND_OUT, OR_OUT : out STD_LOGIC; -- Outputs
NOT_OUT : out STD_LOGIC -- Output for NOT gate
);
end BasicGates;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity DFlipFlop is
Port (
D, CLK : in STD_LOGIC; -- Data and Clock
Q : out STD_LOGIC; -- Output
Q_bar : out STD_LOGIC -- Complementary Output
);
end DFlipFlop;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity FullAdder is
Port (
A, B, Cin : in STD_LOGIC; -- Inputs
Sum, Cout : out STD_LOGIC -- Outputs
);
end FullAdder;
entity RippleCarryAdder is
Port (
A, B : in STD_LOGIC_VECTOR(3 downto 0); -- 4-bit Inputs
Cin : in STD_LOGIC; -- Carry In
Sum : out STD_LOGIC_VECTOR(3 downto 0); -- Sum Output
Cout : out STD_LOGIC -- Carry Out
);
end RippleCarryAdder;
entity Subtractor is
Port (
A, B : in STD_LOGIC_VECTOR(3 downto 0); -- Inputs
Borrow : in STD_LOGIC; -- Borrow Input
Diff : out STD_LOGIC_VECTOR(3 downto 0); -- Difference Output
Bout : out STD_LOGIC -- Borrow Output
);
end Subtractor;