Go Back   Velocity Reviews > Newsgroups > VHDL
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

VHDL - Multiply using shift, for signed numbers

 
Thread Tools Search this Thread
Old 09-09-2005, 11:32 AM   #1
Default Multiply using shift, for signed numbers


I'm trying to achieve multiply using one or more shift operations. For
example,
A = 5*B can be written as
A = 4*B + B or
A = (B sll 2) + B

Now, B is a signed number, so when I do (B sll 2), the shift operation
doesn't discriminate the sign bit, and I end up losing it (falls off to
the left side).

One solution would be to save the MSb of B, perform 'sll' on the rest,
and concatenate them together. If B were signed(7 downto 0) :
A = ((B(7) & (B(6 downto 0) sll 2)) + B;

Is there a better way to do this, perhaps some built-in function I
couldn't find?

I'm thinking that there has to be an easier way. I'm not concerned
about the overflow (yet). Can anyone help? I'm not that fluent in
VHDL. Thank you.



fastgreen2000@yahoo.com
  Reply With Quote
Old 09-12-2005, 11:36 AM   #2
Hubble
 
Posts: n/a
Default Re: Multiply using shift, for signed numbers
I think you misunderstood something. signed is two's complement, so
using 8 bits you have

2: 00000010
1: 00000001
0: 00000000
-1: 11111111
-2: 11111110
-3: 11111101
-4: 11111100

if you shift left, sign bits won't fall off.

Hubble.



Hubble
  Reply With Quote
Old 09-13-2005, 06:08 AM   #3
Hubble
 
Posts: n/a
Default Re: Multiply using shift, for signed numbers
Having thought a bit on this topic, the sll operator does not multiply
by 2**n on 2s complement negative numbers. Since you want to use Logic
Half- and fulladdres, 2s complement should be the representation of
choice. (Note: If you use a sign bit and a mantissa, you have to
redefine the +/- operations as well).

So you have to convert a negative number to a positive, shift, add and
invert it again, like this (without test)

variable highbit: std_logic;
...
highbit:=B(B'high);
if highbit='1' then
B:=abs(B);
end if;
Btimes5:=B ssl 4 + B;
if highbit='1' then
Btimes5:=-Btimes5;
end if;

Hubble.



Hubble
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Numbers and more numbers... Linda A+ Certification 1 12-03-2005 12:43 AM
Re: Numbers and more numbers... Breedo A+ Certification 0 12-02-2005 12:45 AM
Re: Laptop won't type numbers Bill A+ Certification 0 06-10-2005 08:49 PM
Re: Laptop won't type numbers rainman A+ Certification 0 06-08-2005 03:11 AM
"The biggest scandal to ever hit American politics" Jas DVD Video 149 12-05-2004 02:47 PM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46