Digital Assignment 2
Digital Assignment 2
R. YOGITHA LAKSHMI
3122223001124
Submitted By
R. YOGITHA LAKSHMI
3122223001124
R. YOGITHA LAKSHMI
3122223001124
begin
R. YOGITHA LAKSHMI
3122223001124
less_than_B <= tempL(0) or (tempE(0) and tempL(1)) or ((tempE(0) and tempE(1) and
tempL(2)) or (tempE(0) and tempE(1) and tempE(1) and tempE(2) and tempL(3)));
Equal_to_B <= tempE(0) and tempE(1) and tempE(2) and tempE(3);
Greater_than_B <= (((tempG(0) or (tempE(0) and tempG(1)))) or ((tempE(0) and
tempG(2)) or (tempE(0) and tempE(1) and tempE(2) and tempG(3)))); end structural;
Test Bench Code:
begin
-- hold reset state for 100 ns.
A <= "0000";
B <= "0010";
"0010"; wait
"1000"; B <=
"0010"; wait
"1000"; B <=
"0100"; wait
end process;
R. YOGITHA LAKSHMI
3122223001124
2. Write the VHDL code for a 4-bit ripple carry adder using structural modelling and verify
the result using test bench.
VHDL code:
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); S : out STD_LOGIC_VECTOR (4 downto
0)); end RIPPLE_ADDER;
end Structural;
Test Bench:
begin
A <= "1011";
B <= "1101";
wait for 100 ns;
A <= "1011";
B <= "1001";
A <= "1011";
B <= "0101";
A <= "1001";
B <= "0001";
3. Write the VHDL code for a 4 to 16 Decoder using 3:8 decoders (Structural modelling –
Package) and verify the result using test bench.
VHDL Code:
library IEEE; use
IEEE.STD_LOGIC_1164.ALL;
entity Four_to_Sixteen_decoder is
Port ( A : in STD_LOGIC_VECTOR (3 downto 0);
Y : out STD_LOGIC_VECTOR (15 downto 0)); end
Four_to_Sixteen_decoder;
component Three_to_eight_decoder is
Port ( A : in STD_LOGIC_VECTOR(2 downto 0);
E : in STD_LOGIC;
Y : out STD_LOGIC_VECTOR (7 downto 0));
end component;
end structural;
A <= "0010";
wait for 100 ns;
A <= "0011";
wait for 100 ns;
A <= "1100";
wait for 100 ns;
A <= "1111";
wait for 100 ns;
R. YOGITHA LAKSHMI
3122223001124
4. Write a VHDL code for 64:1 multiplexer using 8:1 multiplexer (Structural modelling –
Package) and verify the result using test bench.
VHDL Code (Using data flow model):
library IEEE; use
IEEE.STD_LOGIC_1164.ALL; entity
Sixtyfour_to_one_mux is
Port ( A : in STD_LOGIC_VECTOR (63 downto 0);
S : in STD_LOGIC_VECTOR (5 downto
0); Y : out STD_LOGIC); end
Sixtyfour_to_one_mux;
MUX0: Eight_to_One_MUX port map ( A(7 downto 0), S(2 downto 0), temp(0) );
MUX1: Eight_to_One_MUX port map ( A(15 downto 8), S(2 downto 0), temp(1) );
MUX2: Eight_to_One_MUX port map ( A(23 downto 16), S(2 downto 0), temp(2) );
MUX3: Eight_to_One_MUX port map ( A(31 downto 24), S(2 downto 0), temp(3) );
MUX4: Eight_to_One_MUX port map ( A(39 downto 32), S(2 downto 0), temp(4) );
MUX5: Eight_to_One_MUX port map ( A(47 downto 40), S(2 downto 0), temp(5) );
MUX6: Eight_to_One_MUX port map ( A(55 downto 48), S(2 downto 0), temp(6) );
MUX7: Eight_to_One_MUX port map ( A(63 downto 56), S(2 downto 0), temp(7) );
MUX8: Eight_to_One_MUX port map ( temp, S(5 downto 3), Y );
end Structural;
Test Bench Code:
A <= "0000000000000000000000000000000000000000000000000000000000000001";
S <= "000000";
wait for 100 ns;
A <=
"1111111111111111111111111111111111111111111111111111111111111111";
S <= "000011";
wait for 100 ns;
A <=
"1010101010101010101010101010101010101010101010101010101010101010";
S <= "010101";
wait for 100 ns;
A <=
R. YOGITHA LAKSHMI
3122223001124
"0101010101010101010101010101010101010101010101010101010101010101";
S <= "101010";
wait for 100 ns;
A <=
"0000111100001111000011110000111100001111000011110000111100001111";
S <= "111111";
wait for 100 ns;
OUTPUT:
5. Write the VHDL code for encoder and decoder using dataflow and behavioural modelling and
verify the result using test bench.
1) Encoder (4:2)
VHDL Code (Behavioural):
begin
process(a)
begin
case a is
end process;
end Behavioral;
Test bench Code: a
<= "0001"; wait
for 100 ns;
a <= "0010";
wait for 100 ns;
R. YOGITHA LAKSHMI
3122223001124
a <= "0100";
wait for 100 ns;
a <= "1000";
wait for 100 ns;
OUTPUT:
Behavioural Model:
R. YOGITHA LAKSHMI
3122223001124
Data flow model:
Decoders (2:4):
VHDL (Behavioural Model):
library IEEE; use
IEEE.STD_LOGIC_1164.ALL;
entity decoder4to2ass is
Port ( a : in STD_LOGIC_VECTOR (1 downto 0);
y : out STD_LOGIC_VECTOR (3 downto 0)); end
decoder4to2ass;
begin
begin
process(a)
begin
end process;
end Behavioral;
Test Bench Code:
a <= "00";
R. YOGITHA LAKSHMI
3122223001124
wait for 100 ns;
a <= "01";
wait for 100 ns;
a <= "10";
wait for 100 ns;
a <= "11";
wait for 100 ns;
OUTPUT (Data flow);