Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 1.36 KB | None | 0 0
  1. library IEEE;
  2.     use IEEE.std_logic_1164.all;
  3.     use IEEE.numeric_std.all;
  4.  
  5. entity rippleCarry_adder is
  6.     generic (
  7.         N : integer :=8
  8.     );
  9.    
  10.     port (
  11.          C_IN: IN STD_LOGIC;
  12.         C_OUT: OUT STD_LOGIC;
  13.        
  14.           A,B: IN  SIGNED (0 to N-1);
  15.             S: OUT SIGNED (0 to N-1)
  16.     );
  17. end entity;
  18.  
  19. architecture rtl of rippleCarry_adder is
  20.    
  21.     --INTERNAL SIGNALS    
  22.     signal c : STD_LOGIC_VECTOR (0 to N );--INTERNAL CARRY
  23.     signal c_p : STD_LOGIC_VECTOR (0 to N-1); --used to initialize c vector
  24.     signal s_i : SIGNED (0 to N-1);
  25.    
  26.     component fulladder port (  
  27.                 A : in STD_LOGIC;
  28.                 B : in STD_LOGIC;
  29.               Cin : in STD_LOGIC;
  30.                 S : out STD_LOGIC;
  31.              Cout : out STD_LOGIC
  32.      );
  33. end component;
  34.    
  35.    
  36. begin
  37.    
  38.     c_p <= (others => '0');
  39.     c<= C_IN & c_p; --set it as c_in followed by zeros
  40.    
  41.     full_adder_gen: for i in 0 to N-1  generate
  42.         full_adder_n: fulladder port map (
  43.            Cin   => c(i),
  44.            A     => A(i),
  45.            B     => B(i),
  46.            S     => S(i),
  47.            Cout  => c(i+1)                    
  48.        );
  49.        
  50.       C_OUT <= c(N); --the carry out of the ripple-carry adder is the carry out of the last full adder
  51.    
  52.  
  53.     end generate;
  54.    
  55.    
  56. end architecture;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement