Velocity Reviews > VHDL > signed multiplication

# signed multiplication

priya
Guest
Posts: n/a

 11-16-2006
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

Niv
Guest
Posts: n/a

 11-16-2006
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
Guest
Posts: n/a

 11-17-2006
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.

 Thread Tools

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post William Hughes C Programming 13 03-15-2010 02:04 PM knight VHDL 14 09-09-2008 03:50 PM Weng Tianxiang VHDL 4 04-07-2005 04:10 PM Christopher Dyken C Programming 18 02-24-2004 09:05 AM

Advertisments