8x16 Bit unsigned multiply routine for 8051?

8x16 Bit unsigned multiply routine for 8051?

Post by Neil Bradle » Tue, 26 Nov 2002 07:12:15



Does anyone happen to have an 8 bit by 16 bit unsigned multiply routine for
the 8051? I've found a lot of 16x16 and whatnot, but no 8x16. Any advice
would be greatly appreciated!

-->Neil

 
 
 

8x16 Bit unsigned multiply routine for 8051?

Post by Spehro Pefhan » Tue, 26 Nov 2002 08:18:21


On Sun, 24 Nov 2002 14:12:15 -0800, the renowned "Neil Bradley"


>Does anyone happen to have an 8 bit by 16 bit unsigned multiply routine for
>the 8051? I've found a lot of 16x16 and whatnot, but no 8x16. Any advice
>would be greatly appreciated!

Write it yourself! It's child's play with the 8 x 8 multiply
instruction. Partial products.

Best regards,
Spehro Pefhany
--
"it's the network..."                          "The Journey is the reward"

Embedded software/hardware/analog  Info for designers:  http://www.speff.co

 
 
 

8x16 Bit unsigned multiply routine for 8051?

Post by Jonathan Kirwa » Tue, 26 Nov 2002 16:33:53


On Sun, 24 Nov 2002 23:18:21 GMT, Spehro Pefhany


>On Sun, 24 Nov 2002 14:12:15 -0800, the renowned "Neil Bradley"

>>Does anyone happen to have an 8 bit by 16 bit unsigned multiply routine for
>>the 8051? I've found a lot of 16x16 and whatnot, but no 8x16. Any advice
>>would be greatly appreciated!

>Write it yourself! It's child's play with the 8 x 8 multiply
>instruction. Partial products.

With potentially signed values and using only unsigned mults, I
might imagine a slight pause.  But only a slight one.  It is
rather elementary, regardless.

But since the OP wants advice, so ...

You have an 8-bit unsigned multiplier and a 16-bit unsigned
multiplicand.  You only have an unsigned 8x8 multiply
instruction on the 8051, yes?  Okay.

Break up the multiplicand into two 8-bit unsigned parts.  The
upper half and the lower half.  The upper half is A, the lower
half is B.  Altogether, the multiplicand is then (A*2^8 + B).

The 8-bit unsigned multiplier is, let's say, C.

Thus, you are computing:

  (A*2^8 + B) * C
  A*C*2^8 + B*C

So, you need to compute two [8x8 --> 16] multiplications, one
A*C and one B*C.  Let's say the result of A*C is also broken up
into two 8-bit parts, so that it is (R*2^8 + S) and that the
result of B*C is also broken up into two 8-bit parts, so that it
is (T*2^8 + U).  You compute the following sum:

   R  S
 +    T  U
-----------

If you only need a 16-bit result and already know that R will
always be 0, then you can simply do an 8-bit add of S and T to
get the upper 8 bits of the result and use U as the lower 8
bits.  If you don't know that R=0, then you can S+T and bring
any carry into R and you are done with the 24-bit product.

With signed values and using an exclusively unsigned multiply,
there is a small 'detail' involved.  But we won't go there, for
now.  Two 8x8 multiplies and an 8- or 16-bit sum.  That's really
not much.

Now, try working out the 'little detail' in the case where one
or both values are signed 2's complement values and you are
still stuck using an unsigned 8x8 multiply ...

Jon

 
 
 

8x16 Bit unsigned multiply routine for 8051?

Post by tom » Wed, 27 Nov 2002 02:09:32


  Booths alg'........    many ways to do it .    Hardware mult' takes a lot
of
work out of it .....

 I once wasted  time thinking about how to efficiently do the biggest most
useful number using the least bytes .
  3 ,4  or 5 bytes ?
Star with 4 . Do you store both signs in the last byte and the remaining
6 bits for exponent ?   -/+ 32 ?   Naaa , math types will grumble about
range !
 But robot controllers would like it .
 Do you treat it as one big mantissa , or split it at the dec( bin') point ?
 In mult/division there is a perk with this method .

Lots of question askers here , few answers ....
But i allways like Sphero's help , good work ....

 k c 7 c c at hotmail  ................       Bangkok  1 66 2 542 2080 1314


> On Sun, 24 Nov 2002 14:12:15 -0800, the renowned "Neil Bradley"

> >Does anyone happen to have an 8 bit by 16 bit unsigned multiply routine
for
> >the 8051? I've found a lot of 16x16 and whatnot, but no 8x16. Any advice
> >would be greatly appreciated!

> Write it yourself! It's child's play with the 8 x 8 multiply
> instruction. Partial products.

> Best regards,
> Spehro Pefhany
> --
> "it's the network..."                          "The Journey is the reward"


http://www.trexon.com
Quote:> Embedded software/hardware/analog  Info for designers:

http://www.speff.co
 
 
 

8x16 Bit unsigned multiply routine for 8051?

Post by Jonathan Kirwa » Wed, 27 Nov 2002 03:32:15




Quote:>Booths alg
><snip>

I wonder how many in comp.arch.embedded (where I'm posting from)
have any familiarity with Booth's.  For sequential logic, it's
handy.  But on a micro that already has an 8x8 mult, it's not
terribly useful.  Still, there are times when it's handy to
remember.

Jon