Unit2 VHDL Prog
Unit2 VHDL Prog
Structural Method :
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity Full_Adder_Structural is
port(
A, B, Cin : in std_logic;
Sum, Cout : out std_logic
);
end Full_Adder_Structural;
component AND_Gate
port(
A, B : in std_logic;
Y : out std_logic
);
end component;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity Full_Adder_Dataflow is
port(
A, B, Cin : in std_logic;
Sum, Cout : out std_logic
);
end Full_Adder_Dataflow;
Behavioral Method :
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity Full_Adder_Behavioral is
port(
A, B, Cin : in std_logic;
Sum, Cout : out std_logic
);
end Full_Adder_Behavioral;
Structural Method :
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity Full_Subtractor_Structural is
port(
A, B, Bin : in std_logic;
Diff, Bout : out std_logic
);
end Full_Subtractor_Structural;
component AND_Gate
port(
A, B : in std_logic;
Y : out std_logic
);
end component;
component NOT_Gate
port(
A : in std_logic;
Y : out std_logic
);
end component;
entity Full_Subtractor_Dataflow is
port(
A, B, Bin : in std_logic;
Diff, Bout : out std_logic
);
end Full_Subtractor_Dataflow;
Behavioral Method :
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity Full_Subtractor_Behavioral is
port(
A, B, Bin : in std_logic;
Diff, Bout : out std_logic
);
end Full_Subtractor_Behavioral;
Structural Method :
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity Decoder_Structural is
port(
A, B : in std_logic;
Y0, Y1, Y2, Y3 : out std_logic
);
end Decoder_Structural;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity Decoder_Dataflow is
port(
A, B : in std_logic;
Y0, Y1, Y2, Y3 : out std_logic
);
end Decoder_Dataflow;
Behavioral Method :
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity Decoder_Behavioral is
port(
A, B : in std_logic;
Y0, Y1, Y2, Y3 : out std_logic
);
end Decoder_Behavioral;
Structural Method :
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity Priority_Encoder_Structural is
port(
I0, I1, I2, I3 : in std_logic;
Y0, Y1 : out std_logic
);
end Priority_Encoder_Structural;
Behavioral Method :
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity Priority_Encoder_Behavioral is
port(
I0, I1, I2, I3 : in std_logic;
Y0, Y1 : out std_logic
);
end Priority_Encoder_Behavioral;
Multiplexer :
Structural Method :
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity Multiplexer_Structural is
port(
A, B : in std_logic;
S : in std_logic;
Y : out std_logic
);
end Multiplexer_Structural;
component OR_Gate
port(
A, B : in std_logic;
Y : out std_logic
);
end component;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity Multiplexer_Dataflow is
port(
A, B : in std_logic;
S : in std_logic;
Y : out std_logic
);
end Multiplexer_Dataflow;
Behavioral Method :
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity Multiplexer_Behavioral is
port(
A, B : in std_logic;
S : in std_logic;
Y : out std_logic
);
end Multiplexer_Behavioral;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity Barrel_Shifter_Dataflow is
port (
A : in std_logic_vector(7 downto 0);
shift_amount : in std_logic_vector(2 downto 0);
direction : in std_logic; -- '0' for right shift, '1' for left shift
Y : out std_logic_vector(7 downto 0)
);
end Barrel_Shifter_Dataflow;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity Keyboard_Encoder_Dataflow is
port (
Row : in std_logic_vector(3 downto 0);
Col : in std_logic_vector(3 downto 0);
Key : out std_logic_vector(3 downto 0)
);
end Keyboard_Encoder_Dataflow;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
entity Multiplier_Dataflow is
port (
A, B : in std_logic_vector(3 downto 0);
P : out std_logic_vector(7 downto 0)
);
end Multiplier_Dataflow;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
entity Divider_Dataflow is
port (
A, B : in std_logic_vector(3 downto 0);
Q : out std_logic_vector(3 downto 0);
R : out std_logic_vector(3 downto 0)
);
end Divider_Dataflow;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity Hamming_Code is
port (
Data_In : in std_logic_vector(4 downto 1);
Encoded_Out : out std_logic_vector(7 downto 1);
Corrected_Out : out std_logic_vector(4 downto 1)
);
end Hamming_Code;
-- Encoded output
Encoded_Out <= Data_In(4) & Data_In(3) & Data_In(2) & P8 & Data_In(1) & P4 &
P2 & P1;
-- Error correction
Syndrome <= P1 xor P2 xor P4 xor Data_In(1) xor Data_In(2) xor Data_In(3) xor
Data_In(4);
Corrected_Out <= Data_In;
if Syndrome /= '0' then
case Syndrome is
when "0001" =>
Corrected_Out(1) <= not Corrected_Out(1);
when "0010" =>
Corrected_Out(2) <= not Corrected_Out(2);
when "0100" =>
Corrected_Out(3) <= not Corrected_Out(3);
when "1000" =>
Corrected_Out(4) <= not Corrected_Out(4);
when others =>
null;
end case;
end if;
end Dataflow;
NOTES :