General multiplication

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

General multiplication

Jump to solution
2,142 Views
c64
Contributor I

Hi,

 

This is a general MCU question, and not really addressed to a particular architecture. Say you have an 8-bit MCU that can do 8-bit x 8-bit unsigned integer multiplication, with the result being 16 bits. Would it be possible to use that built-in arithmetic routine to perform a multiplication of M x N bit unsigned integers, where M and N are larger than 8. For instance, would it be possible to perform an 18 x 16 bit unsigned integer multiplication? Not directly of course, but by writing a procedure for it. If so, does anyone have a link to a website describing these algorithms?

 

Thanks!

Labels (1)
0 Kudos
1 Solution
497 Views
kef
Specialist I

Of course 8x8->16bits MUL instructtion can be used to multiply as many bits as you wish. Procedure? Sure you know how to multiply for example 3 decimal digits number by 2 decimal digits number. This algorithm is the same, just replace decimal digits with bytes.

 

     03 FF FF

x        FF FF

     ---------

         FE 01   - first MUL

      

 

     03 FF FF

x        FF FF

     ---------

         FE 01 

+   FE 01        - second MUL

 

 

     03 FF FF

x        FF FF

     ---------

         FE 01 

+  FE 01

02 FD              - 3rd MUL

 

... do another 3 MULs with higher order byte of 2nd multiplier and final picture will be this

 

            03 FF FF

x               FF  FF

            ---------

                FE 01 

+         FE 01

       02 FD              - 3rd

           FE 01 

+     FE 01

  02 FD              - 6th

--------------------

  03 FF FB 00 01 - 18+16 = 34bits product

 

Hope this helps

View solution in original post

0 Kudos
4 Replies
497 Views
c64
Contributor I

Hey guys,

 

Thanks so much for the replies and sample codes! I really appreciate it!

0 Kudos
497 Views
tonyp
Senior Contributor II

And here's a 9S08 assembly language re-entrant routine that multiplies any size (up to 127 bytes) numbers.  For parameter passing simplicity both operands must be of the same size.

0 Kudos
496 Views
bigmac
Specialist III

Hello,

 

The attached code contains functions for 16 x 16 multiply, and 32 x 32 multiply, plus some other division functions.  It extensively makes use of inliine assembly for speed, so is restricted to HC908 and HCS08 devices.

 

Regards,

Mac

 

0 Kudos
498 Views
kef
Specialist I

Of course 8x8->16bits MUL instructtion can be used to multiply as many bits as you wish. Procedure? Sure you know how to multiply for example 3 decimal digits number by 2 decimal digits number. This algorithm is the same, just replace decimal digits with bytes.

 

     03 FF FF

x        FF FF

     ---------

         FE 01   - first MUL

      

 

     03 FF FF

x        FF FF

     ---------

         FE 01 

+   FE 01        - second MUL

 

 

     03 FF FF

x        FF FF

     ---------

         FE 01 

+  FE 01

02 FD              - 3rd MUL

 

... do another 3 MULs with higher order byte of 2nd multiplier and final picture will be this

 

            03 FF FF

x               FF  FF

            ---------

                FE 01 

+         FE 01

       02 FD              - 3rd

           FE 01 

+     FE 01

  02 FD              - 6th

--------------------

  03 FF FB 00 01 - 18+16 = 34bits product

 

Hope this helps

0 Kudos