8 bit times 8 bit multiply optimization

Discussion in 'Embedded Systems and Microcontrollers' started by Markd77, Jan 13, 2011.

  1. Markd77

    Thread Starter Senior Member

    Sep 7, 2009
    2,803
    594
    If I'm only interested in the high byte of the result, I'm wondering if anyone knows any shortcuts to save a bit of time. It's just to scale one value using another.
    This is a fairly standard method in asm for the PIC for the normal multiply, it seems that if I require less precision it might be possible to make it quicker, but I'm rubbish at this sort of thing.
    Code ( (Unknown Language)):
    1. mul8x8m clrf    prodH
    2.             clrf    prodL
    3.             movfw   mulcnd
    4.             clrc
    5.             btfsc   mulplr,0
    6.             addwf   prodH
    7.             rrf     prodH
    8.             rrf     prodL
    9.             btfsc   mulplr,1
    10.             addwf   prodH
    11.             rrf     prodH
    12.             rrf     prodL
    13.             btfsc   mulplr,2
    14.             addwf   prodH
    15.             rrf     prodH
    16.             rrf     prodL
    17.             btfsc   mulplr,3
    18.             addwf   prodH
    19.             rrf     prodH
    20.             rrf     prodL
    21.             btfsc   mulplr,4
    22.             addwf   prodH
    23.             rrf     prodH
    24.             rrf     prodL
    25.             btfsc   mulplr,5
    26.             addwf   prodH
    27.             rrf     prodH
    28.             rrf     prodL
    29.             btfsc   mulplr,6
    30.             addwf   prodH
    31.             rrf     prodH
    32.             rrf     prodL
    33.             btfsc   mulplr,7
    34.             addwf   prodH
    35.             rrf     prodH
    36.             rrf     prodL
    37.             return
     
  2. wannaBinventor

    Member

    Apr 8, 2010
    179
    4
    I would think at the very least you could get rid of the rrf on the prodL file. That looks different than what I have seen in most multiplication routines I must say. Then again, maybe I'm not remembering correctly.
     
  3. Markd77

    Thread Starter Senior Member

    Sep 7, 2009
    2,803
    594
    I tried that, but can only get rid of the last one, it uses the carry bit from the others in the next step.
     
  4. MMcLaren

    Well-Known Member

    Feb 14, 2010
    759
    116
    You're right...

    Are you multiplying a variable by a variable, or a variable by a constant?

    If using an 18F' device you could get away with just a few instructions by using the hardware multiplier.
     
  5. blueroomelectronics

    AAC Fanatic!

    Jul 22, 2007
    1,758
    98
    +1 on the 18F, the multiply instruction also makes a handy shift register!
     
Loading...