home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / language / forst / bmaths.s < prev    next >
Encoding:
Text File  |  1993-10-23  |  1.5 KB  |  77 lines

  1. ; BMATHS.S: Basic integer maths and logic module
  2. ; Copyright <C> John Redmond 1989, 1990
  3. ; Public domain for non-commercial use.
  4. ;
  5.     section    text
  6.     even
  7. ;
  8. ;_UDMOD:    (u32,u32--u32,u32)
  9. _udmod: movem.l d2/d5,-(a7)
  10.     moveq    #31,d5        ;loop counter
  11.     pop    d2        ;divisor
  12.     pop    d1        ;dividend
  13.     moveq    #0,d0
  14. .udmlp: add.l    d1,d1
  15.     addx.l    d0,d0        ;shift dividend left
  16.     cmp.l    d2,d0        ;can we divide?
  17.     bcs.s    .udm5        ;otherwise branch
  18.     sub.l    d2,d0
  19.     addq.w    #1,d1
  20. .udm5:    dbra    d5,.udmlp
  21.     push    d0        ;remainder
  22.     push    d1        ;quotient
  23.     movem.l (a7)+,d2/d5
  24. udmx:    rts
  25. ;
  26. ; _UMULT: (n16,n16--n32)
  27. _umult:
  28.     pop    d0
  29.     pop    d1
  30.     mulu    d1,d0
  31.     push    d0
  32. umx:    rts
  33. ;
  34. ; _UXMULT:    (u32,u32--u64)
  35. _uxmult: movem.l d2-d3,-(a7)
  36.     clr.l    d3        ;highest word ready for overflow
  37.     move.w    2(a6),d0
  38.     mulu    6(a6),d0
  39.     move.l    d0,d1
  40.     clr.w    d1        ;remove low word
  41.     swap    d1        ;get carry ready in low word
  42.     move.w    (a6),d2
  43.     mulu    6(a6),d2
  44.     add.l    d1,d2        ;build words1&2
  45.     bcc    .nc1
  46.     addq.l    #1,d3        ;carry into top word?
  47. .nc1:    move.w    2(a6),d1
  48.     mulu    4(a6),d1
  49.     add.l    d1,d2        ;add to words1&2
  50.     bcc    .nc2
  51.     addq.l    #1,d3        ;carry into top word?
  52. .nc2:    move.w    (a6),d1
  53.     mulu    4(a6),d1    ;build top word
  54.     swap    d1
  55.     add.w    d1,d3        ;word3 of product
  56.     clr.w    d1        ;strip high half
  57.     add.l    d1,d2        ;complete words 1 & 2
  58.     bcc    .nc3
  59.     addq.l    #1,d3
  60. .nc3:    move.w    d0,6(a6)
  61.     move.l    d2,2(a6)
  62.     move.w    d3,(a6)
  63.     movem.l (a7)+,d2-d3
  64. uxmx:    rts
  65. ;
  66.     section    data
  67.     even
  68. ;
  69.      dc.b    $85,'U/MO','D'!$80
  70.     lptrs    _udmod,(udmx-_udmod)/2,18
  71. ;
  72.     dc.b    $83,'UM','*'!$80
  73.     lptrs    _uxmult,(uxmx-_uxmult)/2,16
  74. ;
  75.     dc.b    $82,'U*',$a0
  76.     lptrs    _umult,(umx-_umult)/2,16
  77.