Tut 6 Digital VHDL
Tut 6 Digital VHDL
Q.1
library IEEE; use IEEE.STD_LOGIC_1164.ALL; entity multi_plexer is port ( a, b, c, d, e, f, g, h : in std_logic; Sel : in std_logic_vector(2 downto 0); Output : out std_logic ); end entity multi_plexer; architecture Behavioral of multi_plexer is begin process (a, b, c, d, e, f, g, h, Sel) is begin case Sel is when "000" => Output <= a; when "001" => Output <= b; when "010" => Output <= c; when "011" => Output <= d; when "100" => Output <= e; when "101" => Output <= f; when "110" => Output <= g; when others => Output <= h; end case; end process;
Lo
Logic Diagram
entity fulladder_subt is port ( A, B :in std_logic_vector(3 downto 0); --inputs for each level M :in std_logic; --input carry is M SUM : out std_logic_vector(3 downto 0); --output sum for each level cout, V :out std_logic); --output carry end fulladder_subt; architecture struct_fulladder_subt of fulladder_subt is signal C: std_logic_vector (3 downto 0); component FULL_ADDER port ( A,B,C,M : in std_logic; S, carry : out std_logic); end component; begin FA0: FULL_ADDER Port map (A(0), B(0), M, M, SUM(0), C(0)); FA1: FULL_ADDER Port map (A(1), B(1), C(0), M, SUM(1), C(1)); FA2: FULL_ADDER Port map (A(2), B(2), C(1), M, SUM(2), C(2)); FA3: FULL_ADDER Port map (A(3), B(3), C(2), M, SUM(3), C(3)); Cout <= C(3); V <= C(3) xnor C(2); end struct_fulladder_subt;
library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; use IEEE.STD_LOGIC_ARITH.ALL; entity FULL_ADDER is port ( A,B,C,M : in std_logic; S,Carry : out std_logic); end FULL_ADDER; architecture Behavioral of FULL_ADDER is begin S<= (A xor (B xor M) ) xor C; Carry<= (A and (B xor M) ) or ( C and (A xor (B xor M) ) ); end Behavioral;
Logic Diagram
Logic Diagram
entity Priority_encod is port ( sel : in std_logic_vector (7 downto 0); EI : in std_logic; Output : out std_logic_vector(2 downto 0); GS, EO : out std_logic); end entity Priority_encod; architecture Behavioral of Priority_encod is begin process (sel, EI)
begin EO <= '1'; if(EI = '0') then GS <= '0'; if sel(7)='0' then output <= "000"; elsif sel(6) = '0' then output <= "001"; elsif sel(5) = '0' then output <= "010"; elsif sel(4) = '0' then output <= "011"; elsif sel(3) = '0' then output <= "100"; elsif sel(2) = '0' then output <= "101"; elsif sel(1) = '0' then output <= "110"; elsif sel(0) = '0' then output <= "111"; else output <= "111"; GS <= '1'; EO <= '0'; end if; else GS <= '1'; output <= "111"; end if; end process; end architecture Behavioral;
Logic Diagram
Q.4
library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; use IEEE.STD_LOGIC_ARITH.ALL;
entity Answer_4 is port (a,b,c,d,e,f:in std_logic; O: out std_logic_vector(7 DOWNTO 0)); end Answer_4; architecture Behavioral of Answer_4 is begin O(0)<=a or b or c or d; O(1)<=a or b or (not c) or d; O(2)<=a or b or c or (not d); O(3)<=a or b or (not c) or (not d); O(4)<=(not c) and (not d) and (not(e and f)); O(5)<=(c) and (not d) and (not(e and f)); O(6)<=(not c) and (d) and (not(e and f)); O(7)<=(c) and (d) and (not(e and f));
end Behavioral;
Q.5
library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; use IEEE.STD_LOGIC_ARITH.ALL; entity compare_inp is port (A : in std_logic_vector(3 downto 0); B : in std_logic_vector(3 downto 0); less :out std_logic; equal : out std_logic; greater :out std_logic); end compare_inp; architecture Behavioral of compare_inp is begin process (A, B) begin if (A < B ) then less <= '1'; equal <= '0'; greater <= '0'; elsif (A < B) then less <= '0'; equal <= '0'; greater <= '1'; else less <= '0'; equal <= '1'; greater <= '0'; end if; end process; end Behavioral;
Logic Diagram