Professional Documents
Culture Documents
entity decoder is
port(a, b, c: in bit;
y: out bit_vector(0 to 7));
end entity;
architecture decoder_arch of decoder is
begin
process(a, b, c)
variable abar, bbar, cbar: bit;
begin
abar:=not a;
bbar:=not b;
cbar:=not c;
y(0)<= abar and bbar and cbar;
y(1)<= abar and bbar and c;
y(2)<= abar and b and cbar;
y(3)<= abar and b and c;
y(4)<= a and bbar and cbar;
y(5)<= a and bbar and c;
y(6)<= a and b and cbar;
y(7)<= a and b and c;
end process;
end decoder_arch;
--Test Bench
entity decoder_tb is
end entity;
architecture decoder_tb_arch of decoder_tb is
component decoder is
port(a, b, c: in bit;
y: out bit_vector(0 to 7));
end component;
signal a, b, c: bit;
signal y: bit_vector(0 to 7);
begin
inst: decoder port map(a, b, c, y);
process
begin
a<='0'; b<='0'; c<='0';
wait for 100 ns;
a<='0'; b<='0'; c<='1';
wait for 100 ns;
a<='0'; b<='1'; c<='0';
wait for 100 ns;
a<='0'; b<='1'; c<='1';
wait for 100 ns;
a<='1'; b<='0'; c<='0';
wait for 100 ns;
a<='1'; b<='0'; c<='1';
wait for 100 ns;
a<='1'; b<='1'; c<='0';
wait for 100 ns;
a<='1'; b<='1'; c<='1';
--Test Bench
entity mux4_tb is
end entity;
architecture arch_mux4_tb of mux4_tb is
component mux4 is
port (i:in BIT_vector(0 to 3);
s:in BIT_vector(0 to 1);
dd:out BIT);
end component;
signal in1:BIT_vector(0 to 3);
signal in2:BIT_vector(0 to 1);
signal o1:BIT;
begin
inst: mux4 port map (in1,in2,o1);
process
begin
in1<="1001"; in2<="00";
wait for 100 ns;
in1<="1001"; in2<="01";
wait for 100 ns;
in1<="1001"; in2<="10";
wait for 100 ns;
in1<="1001"; in2<="11";
wait for 100 ns;
end process;
end arch_mux4_tb;
--Test Bench
entity mux8_tb is
end entity;
architecture arch_mux8_tb of mux8_tb is
component mux8 is
port (a:in BIT_vector(0 to 7);
sel:in BIT_vector(0 to 2);
d:out BIT);
end component;
signal in1:BIT_vector(0 to 7);
signal in2:BIT_vector(0 to 2);
signal o1:BIT;
begin
inst: mux8 port map (in1,in2,o1);
process
begin
in1<="10010101"; in2<="000";
wait for 100 ns;
in1<="10010001"; in2<="001";
wait for 100 ns;
in1<="10011100"; in2<="010";
wait for 100 ns;
in1<="10010010"; in2<="011";
wait for 100 ns;
end process;
end arch_mux8_tb;
end arch_compare_tb;
end fun2;
in1<='1';
in2<='1';
wait for 100 ns;
end process;
entity full_adder_tb is
end entity;
architecture fun2 of full_adder_tb is
component full_adder is
port(s, c, z:in bit; s2, c2:out bit);
end component;
signal in1,in2,in3,s2,c2 :bit;
begin
inst:full_adder port map(in1,in2,in3,s2,c2);
process
begin
in1<='0';
in2<='0';
wait for 100 ns;
in1<='0';
in2<='1';
wait for 100 ns;
in1<='1';
in2<='0';
wait for 100 ns;
in1<='1';
in2<='1';
wait for 100 ns;
end process;
end fun2;
begin
component dff is
port(d, clk: in bit;
q: out bit);
end component;
--Test Bench
entity shift8_tb is
end entity;
architecture arch_shift8_tb of shift8_tb is
component shift8 is
port(i,clk2: in bit;
o: out bit);
end component;
signal outp,inp,clk:bit;
constant clk_period: time:=100 ns;
begin
inst: shift8 port map(inp, clk, outp);
clk_process:process
begin
clk<='0';
wait for clk_period/2;
clk<='1';
wait for clk_period/2;
end process;
stim_process:process
begin
inp<='1';
wait for clk_period;
inp<='0';
wait for clk_period;
inp<='1';
wait for clk_period;
inp<='0';
wait for clk_period;
inp<='1';
wait for clk_period;
inp<='0';
wait for clk_period;
inp<='1';
wait for clk_period;
end process;
end arch_shift8_tb;