VWV - ESE - Study
VWV - ESE - Study
-- Behavioral Architecture
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity and_gate_behavioral is
Port ( A : in STD_LOGIC;
B : in STD_LOGIC;
Y : out STD_LOGIC);
end and_gate_behavioral;
-- Dataflow Architecture
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity and_gate_dataflow is
Port ( A : in STD_LOGIC;
B : in STD_LOGIC;
Y : out STD_LOGIC);
end and_gate_dataflow;
entity and_gate_tb is
end and_gate_tb;
architecture testbench of and_gate_tb is
signal A_tb, B_tb, Y_tb : STD_LOGIC;
component and_gate_behavioral
Port ( A : in STD_LOGIC;
B : in STD_LOGIC;
Y : out STD_LOGIC);
end component;
begin
UUT: and_gate_behavioral port map (A => A_tb, B => B_tb, Y => Y_tb);
process
begin
-- Test all possible combinations
A_tb <= '0'; B_tb <= '0'; wait for 10 ns;
A_tb <= '0'; B_tb <= '1'; wait for 10 ns;
A_tb <= '1'; B_tb <= '0'; wait for 10 ns;
A_tb <= '1'; B_tb <= '1'; wait for 10 ns;
wait;
end process;
end testbench;
-- OR Gate Implementations
-- Behavioral Architecture
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity or_gate_behavioral is
Port ( A : in STD_LOGIC;
B : in STD_LOGIC;
Y : out STD_LOGIC);
end or_gate_behavioral;
-- Dataflow Architecture
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity or_gate_dataflow is
Port ( A : in STD_LOGIC;
B : in STD_LOGIC;
Y : out STD_LOGIC);
end or_gate_dataflow;
entity nand_gate_behavioral is
Port ( A : in STD_LOGIC;
B : in STD_LOGIC;
Y : out STD_LOGIC);
end nand_gate_behavioral;
-- Dataflow Architecture
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity nand_gate_dataflow is
Port ( A : in STD_LOGIC;
B : in STD_LOGIC;
Y : out STD_LOGIC);
end nand_gate_dataflow;
entity nor_gate_behavioral is
Port ( A : in STD_LOGIC;
B : in STD_LOGIC;
Y : out STD_LOGIC);
end nor_gate_behavioral;
-- Dataflow Architecture
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity nor_gate_dataflow is
Port ( A : in STD_LOGIC;
B : in STD_LOGIC;
Y : out STD_LOGIC);
end nor_gate_dataflow;
entity xor_gate_behavioral is
Port ( A : in STD_LOGIC;
B : in STD_LOGIC;
Y : out STD_LOGIC);
end xor_gate_behavioral;
-- Dataflow Architecture
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity xor_gate_dataflow is
Port ( A : in STD_LOGIC;
B : in STD_LOGIC;
Y : out STD_LOGIC);
end xor_gate_dataflow;
entity half_adder_dataflow is
Port ( A : in STD_LOGIC;
B : in STD_LOGIC;
Sum : out STD_LOGIC;
Carry : out STD_LOGIC);
end half_adder_dataflow;
entity half_adder_tb is
end half_adder_tb;
component half_adder_behavioral
Port ( A : in STD_LOGIC;
B : in STD_LOGIC;
Sum : out STD_LOGIC;
Carry : out STD_LOGIC);
end component;
begin
UUT: half_adder_behavioral port map (A => A_tb, B => B_tb, Sum => Sum_tb, Carry => Carry_tb);
process
begin
-- Test all possible combinations
A_tb <= '0'; B_tb <= '0'; wait for 10 ns;
A_tb <= '0'; B_tb <= '1'; wait for 10 ns;
A_tb <= '1'; B_tb <= '0'; wait for 10 ns;
A_tb <= '1'; B_tb <= '1'; wait for 10 ns;
wait;
end process;
end testbench;
-- Half Subtractor Implementations
-- Dataflow Architecture
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity half_subtractor_dataflow is
Port ( A : in STD_LOGIC;
B : in STD_LOGIC;
Diff : out STD_LOGIC;
Borrow : out STD_LOGIC);
end half_subtractor_dataflow;
entity D_FF_Behavioral is
Port ( D : in STD_LOGIC;
CLK : in STD_LOGIC;
RST : in STD_LOGIC;
Q : out STD_LOGIC;
QN : out STD_LOGIC);
end D_FF_Behavioral;
entity D_FF_Structural is
Port ( D : in STD_LOGIC;
CLK : in STD_LOGIC;
RST : in STD_LOGIC;
Q : out STD_LOGIC;
QN : out STD_LOGIC);
end D_FF_Structural;
-- Master latch
master: master_slave_latch
port map (D => D, EN => clk_inv, RST => RST, Q => master_q);
-- Slave latch
slave: master_slave_latch
port map (D => master_q, EN => CLK, RST => RST, Q => slave_q);
Q <= slave_q;
QN <= not slave_q;
end Structural;
-- =========================================
-- T-FLIP FLOP
-- =========================================
-- Behavioral Architecture
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity T_FF_Behavioral is
Port ( T : in STD_LOGIC;
CLK : in STD_LOGIC;
RST : in STD_LOGIC;
Q : out STD_LOGIC;
QN : out STD_LOGIC);
end T_FF_Behavioral;
Q <= temp_q;
QN <= not temp_q;
end Behavioral;
entity T_FF_Structural is
Port ( T : in STD_LOGIC;
CLK : in STD_LOGIC;
RST : in STD_LOGIC;
Q : out STD_LOGIC;
QN : out STD_LOGIC);
end T_FF_Structural;
DFF: D_FF_Behavioral
port map (D => d_int, CLK => CLK, RST => RST, Q => q_int, QN => QN);
Q <= q_int;
end Structural;
-- =========================================
-- 4:1 MULTIPLEXER
-- =========================================
-- Behavioral Architecture
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity MUX_4to1_Behavioral is
Port ( I0 : in STD_LOGIC;
I1 : in STD_LOGIC;
I2 : in STD_LOGIC;
I3 : in STD_LOGIC;
SEL : in STD_LOGIC_VECTOR(1 downto 0);
Y : out STD_LOGIC);
end MUX_4to1_Behavioral;
-- Dataflow Architecture
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity MUX_4to1_Dataflow is
Port ( I0 : in STD_LOGIC;
I1 : in STD_LOGIC;
I2 : in STD_LOGIC;
I3 : in STD_LOGIC;
SEL : in STD_LOGIC_VECTOR(1 downto 0);
Y : out STD_LOGIC);
end MUX_4to1_Dataflow;
architecture Dataflow of MUX_4to1_Dataflow is
begin
Y <= I0 when SEL = "00" else
I1 when SEL = "01" else
I2 when SEL = "10" else
I3 when SEL = "11" else
'0';
end Dataflow;
-- =========================================
-- 1:4 DEMULTIPLEXER
-- =========================================
-- Behavioral Architecture
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity DEMUX_1to4_Behavioral is
Port ( I : in STD_LOGIC;
SEL : in STD_LOGIC_VECTOR(1 downto 0);
Y0 : out STD_LOGIC;
Y1 : out STD_LOGIC;
Y2 : out STD_LOGIC;
Y3 : out STD_LOGIC);
end DEMUX_1to4_Behavioral;
case SEL is
when "00" => Y0 <= I;
when "01" => Y1 <= I;
when "10" => Y2 <= I;
when "11" => Y3 <= I;
when others => null;
end case;
end process;
end Behavioral;
-- Dataflow Architecture
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity DEMUX_1to4_Dataflow is
Port ( I : in STD_LOGIC;
SEL : in STD_LOGIC_VECTOR(1 downto 0);
Y0 : out STD_LOGIC;
Y1 : out STD_LOGIC;
Y2 : out STD_LOGIC;
Y3 : out STD_LOGIC);
end DEMUX_1to4_Dataflow;