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 / div.asm < prev    next >
Assembly Source File  |  1989-11-06  |  2KB  |  64 lines

  1. ;  An ill-favored thing, sir, but my own.
  2. ;  It is easier to be critical than correct.   Disraeli
  3. ;
  4. ;           Jerry J. Trantow
  5. ;           1560 A East Irving Place
  6. ;           Milwaukee, Wi 53202-1460
  7. ; written especially for Gadget calculation where result is always 32 bits
  8. ; 12 Jan 89 Now does a 64/32 with a 64 bit result
  9. ; 12 Jan 89 64 bit Quotient gets returned in the Dividend
  10. ; 14 Jan 89 passes divisor by value
  11. ; 15 Jan 89 Used Andi, ori to set X Flag
  12. ; 24 Jan 89 Division by 2^31 or larger doesn't seem to work
  13. ;  1 Feb 89 Implemented a 64/32 = 32 bit Quotient Division
  14. ;           NOTE : ONLY USE THE LOWER ULONG i.e. ONLY A 32 bit Quotient
  15.     IFD LATTICE
  16.      CSECT text
  17.      XDEF _QuadDiv68000
  18.     ELSE
  19.          public    _QuadDiv68000
  20.     ENDC
  21.  
  22. _QuadDiv68000:
  23.         link    a5,#0
  24.         movem.l    d2/d3/d5,-(sp)    ; push registers on the stack
  25.  
  26.         move.l    8(a5),a0    ; Points to Dividend  (64 bits)
  27.         move.l  4(a0),d1    ; lower 32 of Dividend
  28.         move.l  (a0),d0         ; upper 32 of Dividend
  29.  
  30.         move.l    12(a5),d2       ; 32 bit divisor
  31.  
  32.         move.l  #64,d5          ; counter for 64 bit operation
  33.  
  34.         clr.l   d3              ; clear the test LONG WORD
  35.         asl.l   #1,d1           ; move a bit into the test position
  36.         roxl.l  #1,d0
  37.         roxl.l  #1,d3
  38.  
  39. _divide cmp.l   d2,d3           ; is dividend > divisor        
  40.         blt     _smallr
  41.  
  42. _largr  sub.l   d2,d3           ; dividend-=divisor
  43.         ori.b   #16,CCR         ; Q0=1  (X Flag)
  44.         bra     _shift
  45.  
  46. _smallr andi.b  #15,CCR         ; Q0=0  (X Flag)
  47.  
  48. _shift  roxl.l  #1,d1           ; shift Quotient into dividend
  49.         roxl.l  #1,d0           ; shift Dividend into test position
  50.         roxl.l  #1,d3
  51.  
  52.         subi.l  #1,d5           ; decrement the counter        
  53.         bne     _divide
  54.  
  55.         move.l   d0,(a0)        ; put the Quotient where it belongs
  56.         move.l   d1,4(a0)
  57.  
  58. .007    movem.l    (sp)+,d2/d3/d5
  59.         unlk    a5
  60.         rts
  61.         end
  62.  
  63.