marcoshuck

Sumador BCD

Dec 15th, 2016
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 1.17 KB | None | 0 0
  1. -- Declaramos librerías
  2. library IEEE;
  3. use IEEE.STD_LOGIC_1164.ALL;
  4. use IEEE.STD_LOGIC_ARITH.ALL;
  5. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  6.  
  7. -- Definimos la entidad del sumador
  8. entity sumador is
  9.     Port (
  10.         A0, A1, A2, A3: in std_logic; -- Entradas A
  11.         B0, B1, B2, B3: in std_logic; -- Entradas B
  12.         Cin: in std_logic; -- Carry de entrada
  13.         Cout: out std_logic; -- Carry de salida
  14.         S0, S1, S2, S3: out std_logic -- Salidas
  15.         );
  16. end sumador;
  17.  
  18. -- Definimos la arquitectura del sumador
  19. architecture behavioral of sumador is
  20. signal A: std_logic_vector(3 downto 0); -- Vector A
  21. signal B: std_logic_vector(3 downto 0); -- Vector B
  22. signal S: std_logic_vector(4 downto 0); -- Vector S con Cout
  23. signal suma: integer;
  24.  
  25. begin
  26.     -- Cargamos el vector A.
  27.     process(A3, A2, A1, A0)
  28.     begin
  29.         A(3) <= A3;
  30.         A(2) <= A2;
  31.         A(1) <= A1;
  32.         A(0) <= A0;
  33.     end process;
  34.     -- Cargamos el vector B.
  35.     process(B3, B2, B1, B0)
  36.     begin
  37.         B(3) <= B3;
  38.         B(2) <= B2;
  39.         B(1) <= B1;
  40.         B(0) <= B0;
  41.     end process;
  42.    
  43.     suma <= conv_integer(A) + conv_integer(B) + conv_integer(Cin);
  44.    
  45.     S <= conv_std_logic_vector(suma, 5);
  46.    
  47.     S0 <= S(0);
  48.     S1 <= S(1);
  49.     S2 <= S(2);
  50.     S3 <= S(3);
  51.     Cout <=  S(4);
  52. end behavioral;
Advertisement
Add Comment
Please, Sign In to add comment