Advertisement
lasthunter657

Untitled

Dec 21st, 2021
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3.  
  4. entity ripple_carry_adder is
  5. generic (
  6. g_WIDTH : natural := 4
  7. );
  8. port (
  9. i_add_term1 : in std_logic_vector(g_WIDTH-1 downto 0);
  10. i_add_term2 : in std_logic_vector(g_WIDTH-1 downto 0);
  11. --
  12. o_result : out std_logic_vector(g_WIDTH downto 0)
  13. );
  14. end ripple_carry_adder;
  15.  
  16.  
  17. architecture rtl of ripple_carry_adder is
  18.  
  19. component full_adder is
  20. port (
  21. i_bit1 : in std_logic;
  22. i_bit2 : in std_logic;
  23. i_carry : in std_logic;
  24. o_sum : out std_logic;
  25. o_carry : out std_logic);
  26. end component full_adder;
  27.  
  28. signal w_CARRY : std_logic_vector(g_WIDTH downto 0);
  29. signal w_SUM : std_logic_vector(g_WIDTH-1 downto 0);
  30.  
  31.  
  32. begin
  33.  
  34. w_CARRY(0) <= '0'; -- no carry input on first full adder
  35.  
  36. SET_WIDTH : for ii in 0 to g_WIDTH-1 generate
  37. i_FULL_ADDER_INST : full_adder
  38. port map (
  39. i_bit1 => i_add_term1(ii),
  40. i_bit2 => i_add_term2(ii),
  41. i_carry => w_CARRY(ii),
  42. o_sum => w_SUM(ii),
  43. o_carry => w_CARRY(ii+1)
  44. );
  45. end generate SET_WIDTH;
  46.  
  47. o_result <= w_CARRY(g_WIDTH) & w_SUM; -- VHDL Concatenation
  48.  
  49. end rtl;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement