home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff269.lzh / PropGadget / mult.asm < prev    next >
Assembly Source File  |  1989-11-06  |  2KB  |  70 lines

  1. ;  Famines will not be stopped by LAKs carrying placards in parades;
  2. ;  famines will be stopped by engineers producing machines that make 
  3. ;  man more productive.                                             deTrebo
  4. ;
  5. ;           Jerry J. Trantow
  6. ;           1560 A East Irving Place
  7. ;           Milwaukee, Wi 53202-1460
  8. ;  8 Jan 89 Needed a 64 bit mult for Calculating Gadgetry
  9. ;  9 Jan 89 Not pretty, but it works
  10. ;  9 Jan 89 Started a 64 bit divide (div.asm)
  11. ; 14 Jan 89 Changed a,b to be passed by value
  12. ;
  13. ;   unsigned 32x32 bit multiple into a QUAD (64)
  14. ;
  15. ; Note that with an 020 these can be done in 1 or 2 instructions mulu.l, divu.l
  16. ; QUAD = |  16  |  16  |  16   |  16   |             
  17. ;                      |     al*bl     |
  18. ;               | ah*bl+al*bh  |
  19. ;        |    ah*bh    |
  20.  
  21.     IFD LATTICE
  22.       CSECT text
  23.       XDEF _QuadMult68000
  24.     ELSE     
  25.           public    _QuadMult68000
  26.     ENDC
  27.  
  28. _QuadMult68000:
  29.         link    a5,#0
  30.         movem.l    a2/d3/d4/d5/d6,-(sp)    ; push registers on the stack
  31.         clr.l   d3        ; clear these for later
  32.         clr.l   d4
  33.         clr.l   d5
  34.         clr.l   d6
  35.         move.w    8(a5),d3    ; high SHORT of a
  36.         move.w  10(a5),d4    ; low SHORT of a
  37.         move.w    12(a5),d5    ; high SHORT b
  38.         move.w  14(a5),d6
  39.         move.l    16(a5),a2    ; points to c
  40.  
  41.         move.w    d4,d0            ; al     
  42.         mulu.w  d6,d0            ; bl*al
  43.         move.l  d0,4(a2)    ; c=bl*al   (Lowest 4 bytes of the QUAD)
  44.  
  45.         move.w  d4,d0            ; al
  46.         mulu.w  d5,d0            ; al*bh
  47.         move.l  d0,(a2)        ; temp storage in high bytes of c
  48.         
  49.         move.w  d3,d0            ; ah
  50.         mulu.w  d6,d0            ; bl*ah
  51.         clr.l   d1        ; Used with the carry
  52.         add.l   (a2),d0        ; al*bh+bl*ah
  53.  
  54.         bcc     .99
  55.         move.l  #10000,d1    ; save the carry
  56.         
  57. .99     move.l  d1,(a2)        ; clear temp storage (propogate carry)
  58.         add.l   d0,2(a2)    ; c=(al*bh+bl*ah)*2^16 (Middle bytes of QUAD c)
  59.         bcc     .777            ; another carry bit to worry about
  60.         move.w  #1,(a2)        ; carry was set
  61.  
  62. .777    move.w  d3,d0        ; ah
  63.         mulu.w  d5,d0        ; bh*ah
  64.         add.l   d0,(a2)        ; c=(ah*bh)*2^32    (High bytes of QUAD c)
  65.  
  66. .98     movem.l    (sp)+,a2/d3/d4/d5/d6
  67.         unlk    a5
  68.         rts
  69.         end
  70.