Computer Architecture Lab: Name - Roll - 12100119111 Section - (B) Computer Science Engineering
Computer Architecture Lab: Name - Roll - 12100119111 Section - (B) Computer Science Engineering
test bench :
-- Code your testbench here
library IEEE;
use IEEE.std_logic_1164.all;
entity and_test is
end and_test;
Architecture behavior of and_test is
component and_gate
port(
a: in std_logic;
b: in std_logic;
f: out std_logic
);
end component;
signal f : std_logic;
begin
stim_proc: process
begin
OUTPUT:
B: or gate=
VHDL CODE:
DESIGN:
-- Simple OR gate design
library IEEE;
use IEEE.std_logic_1164.all;
entity or_gate is
port(
a: in std_logic;
b: in std_logic;
q: out std_logic);
end or_gate;
TEST BENCH:
-- Testbench for OR gate
library IEEE;
use IEEE.std_logic_1164.all;
entity testbench is
-- empty
end testbench;
architecture tb of testbench is
-- DUT component
component or_gate is
port(
a: in std_logic;
b: in std_logic;
q: out std_logic);
end component;
begin
-- Connect DUT
DUT: or_gate port map(a_in, b_in, q_out);
process
begin
a_in <= '0';
b_in <= '0';
wait for 1 ns;
--assert(q_out='0') report "Fail 0/0" severity error;
-- Clear inputs
a_in <= '0';
b_in <= '0';
assert false report "Test done." severity note;
wait;
end process;
end tb;
OUTPUT:
C: not gate :
VHDL CODE:
DESIGN
-- Code your design here
library IEEE;
use IEEE.std_logic_1164.all;
entity not_gate is
port ( a: in STD_LOGIC;
f: out STD_LOGIC);
end not_gate;
architecture Behavioral of not_gate is
begin
f<= a not a;
end Behavioral;
TEST BENCH:
-- Code your testbench here
library IEEE;
use IEEE.std_logic_1164.all;
entity not_test is
end not_test;
Architecture behavior of not_test is
component not_gate
port(
a: in std_logic;
f: out std_logic
);
end component;
begin
stim_proc: process
begin
OUTPUT:
D: nand gate :
VHDL CODE:
DESIGN:
-- Code your design here
library IEEE;
use IEEE.std_logic_1164.all;
entity nand_gate is
port ( a: in STD_LOGIC;
b: in STD_LOGIC;
f: out STD_LOGIC);
end nand_gate;
architecture Behavioral of nand_gate is
begin
f<= a nand b;
end Behavioral;
TEST BENCH :
-- Code your testbench here
library IEEE;
use IEEE.std_logic_1164.all;
entity nand_test is
end nand_test;
Architecture behavior of nand_test is
component nand_gate
port(
a: in std_logic;
b: in std_logic;
f: out std_logic
);
end component;
signal a : std_logic :='0';
signal b : std_logic :='0';
signal f : std_logic;
begin
stim_proc: process
begin
OUTPUT:
E: nor gate :
VHDL CODE:
DESIGN:
-- Code your design here
library IEEE;
use IEEE.std_logic_1164.all;
entity nor_gate is
port ( a: in STD_LOGIC;
b: in STD_LOGIC;
f: out STD_LOGIC);
end and_gate;
architecture Behavioral of nor_gate is
begin
f<= a nor b;
end Behavioral;
TEST BENCH :
-- Code your testbench here
library IEEE;
use IEEE.std_logic_1164.all;
entity nor_test is
end nor_test;
Architecture behavior of nor_test is
component nor_gate
port(
a: in std_logic;
b: in std_logic;
f: out std_logic
);
end component;
signal a : std_logic :='0';
signal b : std_logic :='0';
signal f : std_logic;
begin
stim_proc: process
begin
OUTPUT:
F: xnor gate :
VHDL CODE:
DESIGN :
-- Code your design here
library IEEE;
use IEEE.std_logic_1164.all;
entity xnor_gate is
port ( a: in STD_LOGIC;
b: in STD_LOGIC;
f: out STD_LOGIC);
end xnor_gate;
architecture Behavioral of xnor_gate is
begin
f<= a xnor b;
end Behavioral;
TEST BENCH:
-- Code your testbench here
library IEEE;
use IEEE.std_logic_1164.all;
entity xnor_test is
end xnor_test;
Architecture behavior of xnor_test is
component xnor_gate
port(
a: in std_logic;
b: in std_logic;
f: out std_logic
);
end component;
signal a : std_logic :='0';
signal b : std_logic :='0';
signal f : std_logic;
begin
stim_proc: process
begin
OUTPUT:
G: xor gate :
VHDL CODE:
DESIGN :
-- Code your design here
library IEEE;
use IEEE.std_logic_1164.all;
entity xor_gate is
port ( a: in STD_LOGIC;
b: in STD_LOGIC;
f: out STD_LOGIC);
end xor_gate;
architecture Behavioral of xor_gate is
begin
f<= a xor b;
end Behavioral;
TEST BENCH:
-- Code your testbench here
library IEEE;
use IEEE.std_logic_1164.all;
entity xor_test is
end xor_test;
Architecture behavior of xor_test is
component xor_gate
port(
a: in std_logic;
b: in std_logic;
f: out std_logic
);
end component;
signal a : std_logic :='0';
signal b : std_logic :='0';
signal f : std_logic;
begin
stim_proc: process
begin
OUTPUT:
entity H_adder is
port(
a,b : IN std_logic;
sum,carry : OUT std_logic);
end H_adder;
end dataflow;
TEST BENCH:
-- Code your testbench here
library IEEE;
use IEEE.std_logic_1164.all;
entity half_adder_tb is
end entity;
architecture tb of half_adder_tb is
component H_adder is
port( a,b : IN std_logic;
sum,carry : OUT std_logic);
end component;
begin
stim: process
begin
a <= '0';
b <= '0';
wait for 20 ns;
a <= '0';
b <= '1';
wait for 20 ns;
a <= '1';
b <= '0';
wait for 20 ns;
a <= '1';
b <= '1';
wait for 20 ns;
wait;
end process;
end tb;
OUTPUT:
B : FULL ADDER:
VHDL CODE:
DESIGN:
-- Code your design here
library IEEE;
use IEEE.std_logic_1164.all;
entity full_adder is
port(
a,b,cin : IN std_logic;
FA_sum,FA_carry : OUT std_logic);
end full_adder;
end dataflow;
TEST BENCH:
-- Code your testbench here
library IEEE;
use IEEE.std_logic_1164.all;
entity full_adder_tb is
end entity;
architecture tb of full_adder_tb is
component full_adder is
port(a,b,cin : IN std_logic;
FA_sum,FA_carry : OUT std_logic);
end component;
begin
stim: process
begin
a <= '0';
b <= '0';
cin <= '0';
wait for 10 ns;
a <= '0';
b <= '0';
cin <= '1';
wait for 10 ns;
a <= '0';
b <= '1';
cin <= '0';
wait for 10 ns;
a <= '0';
b <= '1';
cin <= '1';
wait for 10 ns;
wait;
end process;
end tb;
OUTPUT:
EXPERIMENT 3: A: HALF
SUBTRACTOR
VHDL CODE:
DESIGN:
-- Code your design here
library IEEE;
use IEEE.std_logic_1164.all;
entity half_sub is
port( a,b : IN std_logic;
diff,borrow : OUT std_logic);
end half_sub;
end dataflow;
TEST BENCH:
-- Code your testbench here
library IEEE;
use IEEE.std_logic_1164.all;
entity half_sub_tb is
end entity;
architecture tb of half_sub_tb is
component half_sub is
port(a,b : IN std_logic;
diff,borrow : OUT std_logic);
end component;
begin
stim: process
begin
a <= '0';
b <= '0';
wait for 20 ns;
a <= '0';
b <= '1';
wait for 20 ns;
a <= '1';
b <= '0';
wait for 20 ns;
a <= '1';
b <= '1';
wait for 20 ns;
wait;
end process;
end tb;
OUTPUT :
B : FULL SUBTRACTOR.
VHDL CODE:
DESIGN :
-- Code your design here
library IEEE;
use IEEE.std_logic_1164.all;
entity full_sub is
port( a,b,c : IN std_logic;
diff,borrow : OUT std_logic);
end full_sub;
end dataflow;
TEST BENCH:
-- Code your testbench here
library IEEE;
use IEEE.std_logic_1164.all;
entity full_sub_tb is
end entity;
architecture tb of full_sub_tb is
component full_sub is
port(a,b,c : IN std_logic;
diff,borrow : OUT std_logic);
end component;
begin
stim: process
begin
a <= '0';
b <= '0';
c <= '0';
wait for 20 ns;
a <= '0';
b <= '0';
c <= '1';
wait for 20 ns;
a <= '0';
b <= '1';
c <= '0';
wait for 20 ns;
a <= '0';
b <= '1';
c <= '1';
wait for 20 ns;
wait;
end process;
end tb;
OUTPUT:
entity MUX4_1 is
end MUX4_1;
begin
with s select
end dataflow;
TEST BENCH :
-- Code your testbench here
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED. ALL;
entity Mux4_1_tb is
end entity;
architecture tb of Mux4_1_tb is
component MUX4_1 is
signal y :STD_LOGIC;
begin
i => i,
s => s,
y => y);
stim: process
begin
i <= "1010";
s <= "00";
s <= "11";
wait;
end process;
end tb;
OUTPUT :
EXPERIMENT 5: 2*4 DECODER:
VHDL CODE:
DESIGN:
-- Code your design here
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.STD_LOGIC_ARITH. ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity MUX4_1 is
end MUX4_1;
begin
with s select
end dataflow;
TEST BENCH:
-- Code your testbench here
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED. ALL;
entity Mux4_1_tb is
end entity;
architecture tb of Mux4_1_tb is
component MUX4_1 is
signal y :STD_LOGIC;
begin
i => i,
s => s,
y => y);
stim: process
begin
i <= "1010";
s <= "00";
s <= "11";
wait;
end process;
end tb;
OUTPUT:
EXPERIMENT 6:
FULL ADDER USING HALF ADDER:
VHDL CODE:
DESIGN :
-- Code your design here
library IEEE;
use IEEE.std_logic_1164.all;
entity halfadder is
port(a,b:in std_logic;
sum,carry: out std_logic
);
end halfadder;
end process;
end behavioural;
entity fulladder is
port(A,B,C:in std_logic;
SUM,CARRY: out std_logic
);
end fulladder;
TEST BENCH:
-- Code your testbench here
library IEEE;
use IEEE.std_logic_1164.all;
entity testbench is
end testbench;
architecture tb of testbench is
component halfadder is
port(a,b:in std_logic;
sum,carry: out std_logic
);
end component;
component fulladder is
port(
A,B,C: in STD_LOGIC;
SUM,CARRY: out STD_logic);
end component;
begin
DUT: fulladder port map(a_in, b_in,c_in,SUM_out,CARRY_out);
process
begin
a_in <= '1';
b_in <= '0';
c_in <= '1';
wait for 1 ns;
OUTPUT:
EXPERIMENT 7:
RIPPLE CARRY ADDER:
VHDL CODE:
DESIGN:
-- Code your design here
library IEEE;
use IEEE.std_logic_1164.all;
entity Ripple_Adder 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_Adder;
architecture Structural of Ripple_Adder is
component full_adder_vhdl_code
Port ( A : in STD_LOGIC;
B : in STD_LOGIC;
Cin : in STD_LOGIC;
S : out STD_LOGIC;
Cout : out STD_LOGIC);
end component;
signal c1,c2,c3: STD_LOGIC;
begin
FA1: full_adder_vhdl_code port map( A(0), B(0),'0', S(0), c1);
FA2: full_adder_vhdl_code port map( A(1), B(1), c1, S(1), c2);
FA3: full_adder_vhdl_code port map( A(2), B(2), c2, S(2), c3);
FA4: full_adder_vhdl_code port map( A(3), B(3), c3, S(3), Cout);
end Structural;
TEST BENCH:
-- Code your testbench here
library IEEE;
use IEEE.std_logic_1164.all;
ENTITY Tb_Ripple_Adder IS
END Tb_Ripple_Adder;
ARCHITECTURE tb OF Tb_Ripple_Adder IS
COMPONENT Ripple_Adder
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 COMPONENT;
signal A : std_logic_vector(3 downto 0) := (others => '0');
signal B : std_logic_vector(3 downto 0) := (others => '0');
signal Cin : std_logic := '0';
signal S : std_logic_vector(3 downto 0);
signal Cout : std_logic;
BEGIN
uut: Ripple_Adder PORT MAP (
A => A,
B => B,
Cin => Cin,
S => S,
Cout => Cout);
stim_proc: process
begin
wait for 100 ns;
A <= "0110";
B <= "1100";
wait;
end process;
END tb;
OUTPUT:
EXPERIMENT 8: SR FLIP FLOP:
VHDL CODE:
DESIGN :
-- Code your design here
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_ARITH.all;
use IEEE.std_logic_UNSIGNED.all;
entity SR_FLIPFLOP_SOURCE is
port ( S,R,RST,CLK : in STD_LOGIC;
Q,Qb : out STD_LOGIC);
end SR_FLIPFLOP_SOURCE;
begin
process (S,R,RST,CLK)
begin
if (RST = '1') then
Q <= '0';
elsif (RISING_EDGE (CLK))then
if (S /= R) then
Q <= S;
Qb <= R;
elsif (S = '1' AND R = '1') then
Q<= 'Z';
Qb <= 'Z';end if;
end if;
end process;
end behavioral;
TEST BENCH :
-- Code your testbench here
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.STD_LOGIC_ARITH. ALL;
use IEEE.STD_LOGIC_UNSIGNED. ALL;
entity SR_FF_tb is
end entity;
architecture tb of SR_FF_tb is
component SR_FLIPFLOP_SOURCE is
Port (S,R,RST, CLK : in STD_LOGIC;
Q,Qb : out STD_LOGIC);
end component;
begin
uut: SR_FLIPFLOP_SOURCE port map(
S => S,
R => R,
RST => RST,
CLK => CLK,
Q => Q,
Qb => Qb);
Clock: process
begin
end process;
Stim: process
begin
S <= '0';
R <= '0';
wait for 20 ns;
S <= '0';
R <= '1';
wait for 20 ns;
S <= '1';
R <= '0';
wait for 20 ns;
S <= '1';
R <= '1';
wait for 20 ns;
end process;
end tb;
OUTPUT:
………………………
………………………
…….