soustractor 12 bit vhdl ?

Discussion in 'VHDL' started by charko, Apr 27, 2010.

  1. charko

    charko

    Joined:
    Apr 21, 2010
    Messages:
    10
    Hi i am a new designer in vhdl and i want to write a vhdl code soustractor 12 bit. I want to do it in vhdl structural and at first i create an adder 12 bit in i want to use this adder to create soustractor 12 bit. My idea is i should use complement two for the second operand ( A - B = A + (-B)).

    My question is : How can i create a structural vhdl code for soustractor 12 bit ?

    Thank you very much !

    Charko

    NB: Sorry for my bad english!!
     
    charko, Apr 27, 2010
    #1
    1. Advertising

  2. charko

    charko

    Joined:
    Apr 21, 2010
    Messages:
    10
    I think i resolve this problem!

    The vhdl code that i write to do that is :
    library IEEE;
    use IEEE.STD_LOGIC_1164.ALL;
    use IEEE.STD_LOGIC_ARITH.ALL;[​IMG]
    use IEEE.STD_LOGIC_UNSIGNED.ALL;

    ---- Uncomment the following library declaration if instantiating
    ---- any Xilinx primitives in this code.
    --library UNISIM;
    --use UNISIM.VComponents.all;

    entity soustr12 is
    Port ( a : in STD_LOGIC_VECTOR (11 downto 0);
    b : in STD_LOGIC_VECTOR (11 downto 0);
    s : out STD_LOGIC_VECTOR (11 downto 0));
    end soustr12;

    architecture structural of soustr12 is
    component add12
    port ( a : in std_logic_vector(11 downto 0 );
    b: in std_logic_vector(11 downto 0) ;
    s: out std_logic_vector(11 downto 0);
    Cout: out std_logic);
    end component ;
    signal q : std_logic_vector( 11 downto 0 );


    begin
    q(11 downto 0) <= (not B(11 downto 0) ) + 1 ;
    inst1 : add12 port map ( a(11 downto 0)=> a( 11 downto 0),
    b( 11 downto 0)=> q(11 downto 0),
    s( 11 downto 0)=> s (11 downto 0));
    end structural;
    ----------------------------------------------------------------------------
    I think that is rigth because the test bench give me a good result.
     
    charko, Apr 27, 2010
    #2
    1. Advertising

  3. charko

    joris

    Joined:
    Jan 29, 2009
    Messages:
    152
    If you're really looking for a structural solution, wouldn't you prefer to have a carry-in of 1 instead of adding 1 before-hand, and pass in 'not B'?
    That could save a full adder for the incrementing.
     
    joris, Apr 28, 2010
    #3
  4. charko

    charko

    Joined:
    Apr 21, 2010
    Messages:
    10


    hi Joris. ok i try it !!


    Charko
     
    charko, Apr 30, 2010
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. kumar
    Replies:
    8
    Views:
    3,563
    Vikram
    Feb 17, 2004
  2. markryde@gmail.com
    Replies:
    3
    Views:
    1,803
    Timothy Bendfelt
    Jan 19, 2007
  3. afd
    Replies:
    1
    Views:
    8,425
    Colin Paul Gloster
    Mar 23, 2007
  4. benn686@hotmail.com
    Replies:
    9
    Views:
    1,011
    Juha Nieminen
    Aug 22, 2007
  5. Jeff.M
    Replies:
    6
    Views:
    186
    Lasse Reichstein Nielsen
    May 4, 2009
Loading...

Share This Page