miguel747

somador_3bits

May 24th, 2013
612
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 2.31 KB | None | 0 0
  1.  
  2. library IEEE;
  3.  
  4. entity somador_completo is
  5.     port(c_in,x,y   : in bit;
  6.         sum, c_out  : out bit);
  7. end somador_completo;
  8.  
  9. architecture somador_completo_op1 of somador_completo is
  10.     begin
  11.     sum <= c_in xor (x xor y);
  12.     c_out <= ((x xor y) and c_in) or (x and y);
  13. end somador_completo_op1;
  14.  
  15. --architecture somador_completo_op2 of somador_completo is
  16. --  signal s1,s2,s3     : bit;
  17. --  begin
  18. --  s1 <= (x xor y ) after 20 ns;
  19. --  s2 <= (c_in and s1) after 20 ns;
  20. --  s3 <= (x and y) after 20 ns;
  21. --end somador_completo_op2;
  22.  
  23. entity sum_3bits is
  24.     port(
  25.         C_in:   in bit;
  26.         a,b:    in bit_vector(2 downto 0);
  27.         Sum:    out bit_vector(2 downto 0);
  28.         C_out:  out bit
  29.         );
  30. end sum_3bits;
  31.  
  32. architecture sum_3bits_op of sum_3bits is
  33.     component somador_completo
  34.         port(c_in,x,y: in bit;
  35.             sum,c_out:  out bit
  36.             );
  37.     end component;
  38.     signal t1,t2: bit; --signal temporario
  39.     begin
  40.         FA1: somador_completo port map(C_in,a(0),b(0),Sum(0),t1);
  41.         FA2: somador_completo port map(t1,a(1),b(1),Sum(1),t2);
  42.         FA3: somador_completo port map(t2,a(2),b(2),Sum(2),C_out);
  43. end sum_3bits_op;
  44.  
  45. entity simulador_3bits is
  46. end simulador_3bits;
  47.  
  48. architecture simulador_3bits_op of simulador_3bits is
  49.     signal x_sim,y_sim,sum :    bit_vector(2 downto 0);
  50.     signal c_in,c_out : bit;
  51.     component sum_3bits
  52.         port(
  53.         C_in:   in bit;
  54.         a,b:    in bit_vector(2 downto 0);
  55.         Sum:    out bit_vector(2 downto 0);
  56.         C_out:  out bit
  57.         );
  58.     end component;
  59.     begin
  60.         PORT1: sum_3bits port map(C_in=>c_in,a=>x_sim,b=>y_sim,Sum=>sum,C_out=>c_out);
  61.         process
  62.         begin
  63.                 x_sim<="000";
  64.                 y_sim<="000";
  65.                 c_in <= '0';
  66.                 wait for 20 ns;
  67.                 x_sim<="000";
  68.                 y_sim<="000";
  69.                 c_in <= '1';
  70.                 wait for 20 ns;
  71.                 x_sim<="000";
  72.                 y_sim<="111";
  73.                 c_in <= '1';
  74.                 wait for 20 ns;
  75.                 x_sim<="110";
  76.                 y_sim<="100";
  77.                 c_in <= '1';
  78.                 wait for 20 ns;
  79.                 x_sim<="111";
  80.                 y_sim<="000";
  81.                 c_in <= '1';
  82.                 wait for 20 ns;
  83.                 x_sim<="011";
  84.                 y_sim<="101";
  85.                 c_in <= '1';
  86.                 wait for 20 ns;
  87.                 x_sim<="001";
  88.                 y_sim<="110";
  89.                 c_in <= '0';
  90.                 wait for 20 ns;
  91.                 x_sim<="111";
  92.                 y_sim<="111";
  93.                 c_in <= '0';
  94.                 wait for 20 ns;
  95.                 x_sim<="000";
  96.                 y_sim<="100";
  97.                 c_in <= '0';
  98.                 wait for 20 ns;
  99.                 x_sim<="101";
  100.                 y_sim<="110";
  101.                 c_in <= '1';
  102.                 wait for 20 ns;
  103.                 wait;
  104.         end process;
  105. end simulador_3bits_op;
Advertisement