8 bit times 8 bit multiply optimization

Thread Starter

Markd77

Joined Sep 7, 2009
2,806
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.
Rich (BB code):
mul8x8m clrf    prodH
            clrf    prodL
            movfw   mulcnd
            clrc
            btfsc   mulplr,0
            addwf   prodH
            rrf     prodH
            rrf     prodL
            btfsc   mulplr,1
            addwf   prodH
            rrf     prodH
            rrf     prodL
            btfsc   mulplr,2
            addwf   prodH
            rrf     prodH
            rrf     prodL
            btfsc   mulplr,3
            addwf   prodH
            rrf     prodH
            rrf     prodL
            btfsc   mulplr,4
            addwf   prodH
            rrf     prodH
            rrf     prodL
            btfsc   mulplr,5
            addwf   prodH
            rrf     prodH
            rrf     prodL
            btfsc   mulplr,6
            addwf   prodH
            rrf     prodH
            rrf     prodL
            btfsc   mulplr,7
            addwf   prodH
            rrf     prodH
            rrf     prodL
            return
 
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.
 

Thread Starter

Markd77

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

MMcLaren

Joined Feb 14, 2010
861
I tried that, but can only get rid of the last one, it uses the carry bit from the others in the next step.
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.
 
Top