Professional Documents
Culture Documents
Afaq Khaliq
a). Apply HDL modelling technique using VHDL programming language to design 4-bit Arithmetic
Logic Unit (ALU) which can perform the functions enlisted in Table1. (PLO3-C3/CLO5)
b). Display the result using vector waveform (vwf) simulator. (PLO5-P4/CLO6
Main File
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use work.AllComponents.all;
entity Task1 is
port(
sel:in std_logic_vector(3 downto 0);
a,b:in std_logic_vector(7 downto 0);
cin:in std_logic;
y:out std_logic_vector(7 downto 0)
);
end Task1;
package AllComponents is
component Arithematic is
port(
sel: in std_logic_vector(2 downto 0);
a: in std_logic_vector(7 downto 0);
b: in std_logic_vector(7 downto 0);
cin:in std_logic;
y: out std_logic_vector(7 downto 0)
);
end component;
component Logic is
port(
sel: in std_logic_vector(2 downto 0);
a: in std_logic_vector(7 downto 0);
b: in std_logic_vector(7 downto 0);
y: out std_logic_vector(7 downto 0)
);
end component;
end AllComponents;
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity Logic is
port(
FA16-BCE-093 M.Afaq Khaliq
);
end Logic;
begin
process(sel,a,b)
begin
if(sel="000") then
y<=not a;
elsif(sel="001") then
y<=not b;
elsif(sel="010") then
y<=a and b;
elsif(sel="011") then
y<=a or b;
elsif(sel="100") then
y<=a nand b;
elsif(sel="101") then
y<=a nor b;
elsif(sel="110") then
y<=a xor b;
elsif(sel="111") then
FA16-BCE-093 M.Afaq Khaliq
y<=a xnor b;
end if;
end process;
end archi;
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity Arithematic is
port(
cin:in std_logic;
);
end Arithematic;
begin
process(sel,a,b)
begin
if(sel="000") then
y<=a;
elsif(sel="001") then
FA16-BCE-093 M.Afaq Khaliq
y<=a+"00000001";
elsif(sel="010") then
y<=a-"00000001";
elsif(sel="011") then
y<=b;
elsif(sel="100") then
y<=b+"00000001";
elsif(sel="101") then
y<=b-"00000001";
elsif(sel="110") then
y<=a+b;
elsif(sel="111") then
y<=a+b+cin;
end if;
end process;
end archi;
Waveform
FA16-BCE-093 M.Afaq Khaliq