Advertisement
Guest User

bitshift multiplication

a guest
Nov 24th, 2019
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; ---------------------------------------------------------------------------
  2. ; macro to convert multiplication to bit shift (w)
  3. ; in:
  4. ; \1 =  input number
  5. ; out:
  6. ; \2 =  output register
  7. ; to-do: esto es mulu, después hacer un muls, divu, divs?
  8. ; ---------------------------------------------------------------------------
  9.  
  10. omulu:      macro
  11. __sp:       = 0
  12. @do:        macro
  13.         n:  = \1
  14.         i:  = 0
  15.         while   n>1
  16.             n:  = n>>1
  17.             i:  = i+1
  18.         endw
  19.         if  i>8*2
  20.             inform  0,"Warning! Overflow will always give zero result"
  21.             moveq   #0,\2
  22.             mexit
  23.         endif
  24.         if  (1*\1)<>(1<<i)
  25.             __sp:   = __sp+1
  26.             t:  = ((\1)-1<<i)
  27.  
  28.             pushp   '\#n'
  29.             pushp   '\#i'
  30.             move.w  \2,-(__sp*2+2)(sp)      ; -> Very slow #1
  31.             @do t,\2
  32.             move.w  \2,-(sp)
  33.             move.w  -(4-2)(sp),\2           ; -> Very slow #2
  34.             popp    bi
  35.             popp    bn
  36.             n:  = \bn
  37.             i:  = \bi
  38.         endif
  39.         while   i>=8
  40.             ;lsl.w  #8,\2
  41.                 clr.w   -(sp)
  42.                 move.b  \2,(sp)
  43.                 move.w  (sp)+,\2
  44.             i:  = i-8
  45.         endw
  46.         if  i<=2
  47.             rept    i
  48.             add.w   \2,\2
  49.             endr
  50.         else
  51.             lsl.w   #i,\2
  52.         endif
  53.         endm
  54.         @do \1, \2
  55.         rept    __sp
  56.         add.w   (sp)+,\2
  57.         endr
  58.         endm
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement