Shop OBEX P1 Docs P2 Docs Learn Events
Fast MUL in ASM? — Parallax Forums

Fast MUL in ASM?

Nick MuellerNick Mueller Posts: 815
edited 2007-12-14 19:43 in Propeller 1
Hi!

Is there a fast multiply in ASM, or do I have to write my own?
It is a 16bit by 8 bits multiply. Or, if you want, 32 bit by 8 bit without overflow.

Any code snipplets welcome!


Nick

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Never use force, just go for a bigger hammer!

The DIY Digital-Readout for mills, lathes etc.:
YADRO

Comments

  • AleAle Posts: 2,363
    edited 2007-11-29 11:59
    There is a document by Parallax with code for mul. If you unroll it, it is quite fast smile.gif

    ' 
    ' Multiply x[noparse][[/noparse]15..0] by y[noparse][[/noparse]15..0] (y[noparse][[/noparse]31..16] must be 0) 
    ' on exit, product in y[noparse][[/noparse]31..0] 
    ' 
    multiply        shl     x,#16           'get multiplicand into x[noparse][[/noparse]31..16] 
                    mov     t,#16           'ready for 16 multiplier bits 
                    shr     y,#1    wc      'get initial multiplier bit into c 
     
    :loop   if_c    add     y,x     wc      'if c set, add multiplicand into product 
                    rcr     y,#1    wc      'get next multiplier bit into c, shift product 
                    djnz    t,#:loop        'loop until done 
     
    multiply_ret    ret                     'return with product in y[noparse][[/noparse]31..0] 
    
    


    just unrool and enjoy smile.gif

    It is available in "Propeller Guts" wink.gif
  • edited 2007-12-14 18:35
    Now if we could get a 16x16 signed multiply example......


    -Dan

    Post Edited (Direct Digital Labs) : 12/14/2007 6:40:30 PM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2007-12-14 18:41
    It's not hard to do yourself. Use ABS to fetch the X and Y values and do the multiply. Then XOR the original values and shift the sign bit into the carry flag. NEGC will negate the result if the carry flag is true. There you are.
  • deSilvadeSilva Posts: 2,967
    edited 2007-12-14 19:43
    As the MSB will be never set, you can also reduce the loopcount...
Sign In or Register to comment.