signed multiplication

Discussion in 'VHDL' started by priya, Nov 16, 2006.

  1. priya

    priya Guest

    hi all
    Y<=Y+(A*B-C*D);
    where y,A,B,C,D are STD_LOGIC_VECTOR form.
    here A,B,C,D are all variables
    since by default STD_LOGIC_VECTOR is Unsigned .
    so the result which i m getting is not what is required. since its
    taking the unsigned equivalent of A*B and C*D while subtracting
    reply soon
    best regards,
    priya
     
    priya, Nov 16, 2006
    #1
    1. Advertising

  2. priya

    Niv Guest

    priya wrote:
    > hi all
    > Y<=Y+(A*B-C*D);
    > where y,A,B,C,D are STD_LOGIC_VECTOR form.
    > here A,B,C,D are all variables
    > since by default STD_LOGIC_VECTOR is Unsigned .
    > so the result which i m getting is not what is required. since its
    > taking the unsigned equivalent of A*B and C*D while subtracting
    > reply soon
    > best regards,
    > priya


    Assuming you're using ieee.numeric_std, you have to cast SLV's into
    SIGNED or UNSIGNED before doing the math, then cast back to a SLV

    Y <= STD_LOGIC_VECTOR(UNSIGNED(Y) + ((UNSIGNED(A) * (UNSIGNED(B)) -
    (UNSIGNED(C) * UNSIGNED(D)) )

    (Replace UNSIGNED with SIGNED where appropriate. Why not declare A,B,
    C & D as UNSIGNED if they not ports?)

    That's what I'd try anyway,

    Kev P.
     
    Niv, Nov 16, 2006
    #2
    1. Advertising

  3. priya

    priya Guest

    hi
    i had taken y,A,B,C,D are STD_LOGIC_VECTOR
    n tried wat u said
    but ended up wwith failure
    one more thing i want 2 ask i m using max n min function
    for that i had included NUMERIC_STD library.
    still i m ending up with errors
    best regards,
    priya
    Niv wrote:
    > priya wrote:
    > > hi all
    > > Y<=Y+(A*B-C*D);
    > > where y,A,B,C,D are STD_LOGIC_VECTOR form.
    > > here A,B,C,D are all variables
    > > since by default STD_LOGIC_VECTOR is Unsigned .
    > > so the result which i m getting is not what is required. since its
    > > taking the unsigned equivalent of A*B and C*D while subtracting
    > > reply soon
    > > best regards,
    > > priya

    >
    > Assuming you're using ieee.numeric_std, you have to cast SLV's into
    > SIGNED or UNSIGNED before doing the math, then cast back to a SLV
    >
    > Y <= STD_LOGIC_VECTOR(UNSIGNED(Y) + ((UNSIGNED(A) * (UNSIGNED(B)) -
    > (UNSIGNED(C) * UNSIGNED(D)) )
    >
    > (Replace UNSIGNED with SIGNED where appropriate. Why not declare A,B,
    > C & D as UNSIGNED if they not ports?)
    >
    > That's what I'd try anyway,
    >
    > Kev P.
     
    priya, Nov 17, 2006
    #3
    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. Weng Tianxiang
    Replies:
    4
    Views:
    3,147
    Weng Tianxiang
    Apr 7, 2005
  2. Christopher Dyken

    32x32 and 64x64 signed integer multiplication

    Christopher Dyken, Feb 17, 2004, in forum: C Programming
    Replies:
    18
    Views:
    1,456
    glen herrmannsfeldt
    Feb 24, 2004
  3. knight

    Signed multiplication

    knight, Sep 8, 2008, in forum: VHDL
    Replies:
    14
    Views:
    2,786
  4. Andy
    Replies:
    1
    Views:
    500
    Mike Treseler
    Sep 29, 2008
  5. William Hughes
    Replies:
    13
    Views:
    1,273
    Ben Bacarisse
    Mar 15, 2010
Loading...

Share This Page