 
     
    
        
         
     
    
        
        
                        
            
                
                
                
                
            
            
            
                        
                
                
                    URL
                    https://opencores.org/ocsvn/pdp1/pdp1/trunk
                
             
            
            
[/] [pdp1/] [trunk/] [rtl/] [vhdl/] [onecomplement_adder.vhd] - Blame information for rev 3
Details |
Compare with Previous |
View Log
   
      
      | Line No. | Rev | Author | Line | 
   
   
      
         | 1 | 3 | yannv | ----------------------------------------------------------------------------------
 | 
      
         | 2 |  |  | -- Company: 
 | 
      
         | 3 |  |  | -- Engineer: 
 | 
      
         | 4 |  |  | -- 
 | 
      
         | 5 |  |  | -- Create Date:    04:01:09 08/19/2009 
 | 
      
         | 6 |  |  | -- Design Name: 
 | 
      
         | 7 |  |  | -- Module Name:    onecomplement_adder - Behavioral 
 | 
      
         | 8 |  |  | -- Project Name: 
 | 
      
         | 9 |  |  | -- Target Devices: 
 | 
      
         | 10 |  |  | -- Tool versions: 
 | 
      
         | 11 |  |  | -- Description: 
 | 
      
         | 12 |  |  | --
 | 
      
         | 13 |  |  | -- Dependencies: 
 | 
      
         | 14 |  |  | --
 | 
      
         | 15 |  |  | -- Revision: 
 | 
      
         | 16 |  |  | -- Revision 0.01 - File Created
 | 
      
         | 17 |  |  | -- Additional Comments: 
 | 
      
         | 18 |  |  | --
 | 
      
         | 19 |  |  | ----------------------------------------------------------------------------------
 | 
      
         | 20 |  |  | library IEEE;
 | 
      
         | 21 |  |  | use IEEE.STD_LOGIC_1164.ALL;
 | 
      
         | 22 |  |  | --use IEEE.STD_LOGIC_ARITH.ALL;
 | 
      
         | 23 |  |  | --use IEEE.STD_LOGIC_UNSIGNED.ALL;
 | 
      
         | 24 |  |  | use IEEE.NUMERIC_STD.ALL;
 | 
      
         | 25 |  |  |  
 | 
      
         | 26 |  |  | entity onecomplement_adder is
 | 
      
         | 27 |  |  |         generic (width: Integer := 18);
 | 
      
         | 28 |  |  |     Port ( A : in  STD_LOGIC_VECTOR (0 to width-1);
 | 
      
         | 29 |  |  |            B : in  STD_LOGIC_VECTOR (0 to width-1) := (others=>'0');
 | 
      
         | 30 |  |  |            CI : in  STD_LOGIC := '0';                                                                                                            -- TODO: verify whether overflow is handled correctly with CI=1
 | 
      
         | 31 |  |  |                                                 -- it is (so far) only used for the Divide Step instruction, which does not update OV
 | 
      
         | 32 |  |  |            SUM : out  STD_LOGIC_VECTOR (0 to width-1);
 | 
      
         | 33 |  |  |            OV : out  STD_LOGIC;
 | 
      
         | 34 |  |  |            CSUM : out  STD_LOGIC_VECTOR (0 to width-1)); -- cleaned up sum, will not be -0 (all 1s)
 | 
      
         | 35 |  |  | end onecomplement_adder;
 | 
      
         | 36 |  |  |  
 | 
      
         | 37 |  |  | architecture Behavioral of onecomplement_adder is
 | 
      
         | 38 |  |  |         signal s1, s2: unsigned(0 to width);
 | 
      
         | 39 |  |  |         signal c: unsigned(0 to 0);
 | 
      
         | 40 |  |  | begin
 | 
      
         | 41 |  |  |         c <= "1" when CI='1' else "0";
 | 
      
         | 42 |  |  |         s1 <= unsigned('0'&A)+unsigned('0'&B)+c;
 | 
      
         | 43 |  |  |         s2 <= s1+1 when s1(0)='1' else s1;               -- add carry back in for one's complement - very expensive, this got us a second adder!
 | 
      
         | 44 |  |  |         OV <= '1' when s2(1)/=A(0) and A(0)=B(0) else '0';
 | 
      
         | 45 |  |  |         sum <= std_logic_vector(s2(1 to width));
 | 
      
         | 46 |  |  |         csum <= std_logic_vector(s2(1 to width)) when s2(1 to width)/=(2**width-1) else (others=>'0');
 | 
      
         | 47 |  |  | end Behavioral;
 | 
   
 
 
         
                
        
            
            
        
        
             
    
        © copyright 1999-2025
OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.