martes, 12 de julio de 2011

Sumador - Restador

library ieee;
use  ieee.std_logic_1164.all;
use  ieee.std_logic_unsigned.all;

entity suma_resta is
    port ( A, B : in std_logic_vector( 3 downto 0 );
             C0 : in std_logic ;
             S : out  std_logic_vector ( 3 downto 0 );
             C4 : out std_logic );
 end suma_resta;

 architecture  comportamiento_1   of  suma_resta  is
 signal   suma : std_logic_vector( 4 downto 0 );
 begin
        process (A,B,C0)
            begin
                if C0='1' then
                   
                    suma <= ( '0' & A ) + ( '0' & B );
                   
                    else
                    suma <= ( '0' & A ) - ( '0' & B );
                end if;
               
               
               
                C4 <= suma( 4 );
                S <= suma( 3 downto 0 );
        end process;
  end comportamiento_1;

No hay comentarios:

Publicar un comentario