Guest User

Untitled

a guest
Apr 22nd, 2012
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 2.98 KB | None | 0 0
  1. - Uncomment the following library declaration if using
  2. -- arithmetic functions with Signed or Unsigned values
  3. --use IEEE.NUMERIC_STD.ALL;
  4.  
  5. -- Uncomment the following library declaration if instantiating
  6. -- any Xilinx primitives in this code.
  7. --library UNISIM;
  8. --use UNISIM.VComponents.all;
  9.  
  10. entity Somador8bits is
  11.     port(
  12.         operandoA, operandoB: in std_logic_vector(7 downto 0);
  13.         operacao: in std_logic;
  14.         ValorAlto, ValorBaixo: out std_logic_vector(6 downto 0);
  15.         flag_Z, flag_N, flag_C, flag_V: out std_logic
  16.         );
  17. end Somador8bits;
  18.  
  19. architecture Soma8 of Somador8bits is
  20.     signal Bi,n: std_logic_vector(7 downto 0);
  21.     signal s1, s2: std_logic_vector(3 downto 0);
  22.     signal c: std_logic;
  23. begin
  24.     A0: entity work.Somador1bit port map(cin=>c, a=>operandoA(0), b=>Bi(0), cout=>n(0), s=>s1(0));
  25.     A1: entity work.Somador1bit port map(cin=>n(0), a=>operandoA(1), b=>Bi(1), cout=>n(1), s=>s1(1));
  26.     A2: entity work.Somador1bit port map(cin=>n(1), a=>operandoA(2), b=>Bi(2), cout=>n(2), s=>s1(2));
  27.     A3: entity work.Somador1bit port map(cin=>n(2), a=>operandoA(3), b=>Bi(3), cout=>n(3), s=>s1(3));
  28.     A4: entity work.Somador1bit port map(cin=>n(3), a=>operandoA(4), b=>Bi(4), cout=>n(4), s=>s2(0));
  29.     A5: entity work.Somador1bit port map(cin=>n(4), a=>operandoA(5), b=>Bi(5), cout=>n(5), s=>s2(1));
  30.     A6: entity work.Somador1bit port map(cin=>n(5), a=>operandoA(6), b=>Bi(6), cout=>n(6), s=>s2(2));
  31.     A7: entity work.Somador1bit port map(cin=>n(6), a=>operandoA(7), b=>Bi(7), cout=>n(7), s=>s2(3));
  32.    
  33.     with operacao select
  34.         Bi<= not operandoB when '1',
  35.               operandoB when '0';
  36.              
  37.     with s1 select
  38.          ValorBaixo<= "1111110" when "0000",
  39.                           "0110000" when "0001",
  40.                           "1101101" when "0010",
  41.                           "1111001" when "0011",
  42.                           "1100011" when "0100",
  43.                           "1110011" when "0101",
  44.                           "1011111" when "0110",
  45.                           "1110010" when "0111",
  46.                           "1111111" when "1000",
  47.                           "1100111" when "1001",
  48.                           "1110111" when "1010",
  49.                           "0011111" when "1011",
  50.                           "1001110" when "1100",
  51.                           "0111101" when "1101",
  52.                           "1001111" when "1110",
  53.                           "1000111" when "1111";
  54.                          
  55.     with s2 select
  56.         ValorAlto<= "1111110" when "0000",
  57.                         "0110000" when "0001",
  58.                         "1101101" when "0010",
  59.                         "1111001" when "0011",
  60.                         "1100011" when "0100",
  61.                         "1110011" when "0101",
  62.                         "1011111" when "0110",
  63.                         "1110010" when "0111",
  64.                         "1111111" when "1000",
  65.                         "1100111" when "1001",
  66.                         "1110111" when "1010",
  67.                         "0011111" when "1011",
  68.                         "1001110" when "1100",
  69.                         "0111101" when "1101",
  70.                         "1001111" when "1110",
  71.                         "1000111" when "1111";
  72.    
  73.     flag_Z<= '1' when s1 & s2=x"0" else '0';
  74.     flag_N<= '1' when s1 & s2<x"0" else '0';
  75.     flag_C<= n(7);                   
  76.     flag_V<= '1' when ((operacao='1') and ((operandoA>x"0" and Bi>x"0" and S1 & S2<x"0") or (operandoA<x"0" and Bi<x"0" and S1 & S2>x"0"))) or
  77.     ((operacao='0') and ((operandoA>x"0" and Bi>x"0" and S1 & S2<x"0") or (operandoA<x"0" and Bi<x"0" and S1 & S2>x"0")))
  78.     else '0';
  79. end Soma8;
Advertisement
Add Comment
Please, Sign In to add comment