Advertisement
Guest User

Untitled

a guest
May 26th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 1.16 KB | None | 0 0
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3.  
  4. entity sum_1_bit is
  5.     port
  6.     (
  7.     a,b,cin : in std_logic;
  8.     s, cout: out std_logic
  9.     );             
  10. end entity;
  11.  
  12. architecture sum of sum_1_bit is
  13. begin
  14.     cout <= (a and b) or (a and cin) or (b and cin);
  15.     s <= a xor b xor cin;
  16. end architecture;        
  17.  
  18. library ieee;
  19. use ieee.std_logic_1164.all;
  20.  
  21. entity sum_n_biti is
  22.     generic (n : INTEGER range 0 to 10 := 5);
  23.     port
  24.     (
  25.     a,b : in std_logic_vector (n-1 downto 0);
  26.     cin : in std_logic;
  27.     cout : out std_logic;
  28.     s : out std_logic_vector (n-1 downto 0)
  29.     );
  30. end entity;                                  
  31.  
  32. architecture summ of sum_n_biti is       
  33. component sum_1_bit is
  34.     port
  35.     (
  36.     a,b,cin : in std_logic;
  37.     s, cout: out std_logic
  38.     );             
  39. end component;
  40. signal temp : std_logic_vector (n-1 downto 0);
  41. begin
  42.     et1: for i in 0 to n - 1 generate
  43.         et2: if i = 0 generate
  44.             et3: sum_1_bit port map(a(i), b(i), cin, s(i), temp(i));
  45.         end generate;
  46.         et4: if i > 0 and i < n generate
  47.             et5: sum_1_bit port map(a(i), b(i), temp(i-1), s(i), temp(i));
  48.         end generate;
  49.         et6: if i = n generate
  50.             et7: sum_1_bit port map(a(i), b(i), temp(i-1), s(i), cout);
  51.         end generate;
  52.     end generate;
  53. end architecture;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement