home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 466.lha / A68kExamples / RealOut.asm < prev    next >
Assembly Source File  |  1991-02-03  |  3KB  |  139 lines

  1.  
  2. *  RealOut change real number to ASCII string
  3. *
  4. *  IN
  5. *  d0 real number
  6. *  d1 number of mantissa digits - 1
  7. *  a0 pointer to begin of buffer
  8. *  OUT
  9. *  a0 pointer to end of buffer
  10. *
  11. * written by E. Lenz
  12. *            Johann-Fichte-Strasse 11
  13. *            8 Munich 40
  14. *            Germany
  15.  
  16. ***** exec *****
  17.  
  18. _AbsExecBase     equ 4
  19. _LVOCloseLibrary equ -$19e
  20. _LVOOpenLibrary  equ -$228
  21.  
  22. ****** mathffp ******
  23.  
  24. _LVOSPFix        equ -$1e
  25. _LVOSPFlt        equ -$24
  26. _LVOSPCmp        equ -$2a
  27. _LVOSPSub        equ -$48
  28. _LVOSPMul        equ -$4e
  29. _LVOSPDiv        equ -$54
  30.  
  31. one      equ  $80000041
  32. ten      equ  $a0000044
  33.  
  34.  
  35.          XDEF RealOut
  36.  
  37. RealOut  movem.l d4-d7/a1/a3/a6,-(a7)  save used registers
  38.          movea.l a0,a3                 save input data
  39.          move.l  d0,d7
  40.          move.l  d1,d4
  41.          move.l  #ten,d5
  42.          moveq   #0,d6                 exponent = 0
  43.          move.l  _AbsExecBase,a6
  44.          lea     FfpName(pc),a1        open mathffp library
  45.          moveq   #0,d0
  46.          jsr     _LVOOpenLibrary(a6)
  47.          movea.l d0,a6
  48.          tst.l   d0
  49.          beq     exit
  50.  
  51. ; first step - get sign of number
  52.  
  53.          tst.l   d7           throw out zero
  54.          beq.s   reduced
  55.  
  56.          tst.b   d7
  57.          bpl.s   ispos
  58.          move.b  #'-',(a3)+
  59.          bclr    #7,d7         dirty _LVOSPAbs
  60.  
  61. ; second step get exponent i.e. reduce to 1 <=     < 10
  62.  
  63. ispos    move.l  d7,d1
  64.          move.l  #one,d0
  65.          jsr     _LVOSPCmp(a6)
  66.          tst.l   d0
  67.          bmi.s   less           one > value?
  68.          move.l  d7,d1
  69.          move.l  d5,d0
  70.          jsr     _LVOSPCmp(a6)
  71.          tst.l   d0
  72.          bmi.s   reduced        ten > value?
  73.  
  74.          move.l  d5,d1
  75.          move.l  d7,d0
  76.          jsr     _LVOSPDiv(a6)  divide by ten
  77.          addq.l  #1,d6
  78. gopos    move.l  d0,d7         
  79.          bra.s   ispos
  80.  
  81. less     move.l  d5,d1
  82.          move.l  d7,d0
  83.          jsr     _LVOSPMul(a6)  multiply by ten
  84.          subq.l  #1,d6
  85.          bra.s   gopos
  86.  
  87. ; 3rd step write mantissa
  88.  
  89. reduced  move.l  d7,d0
  90.          bsr.s   numeral
  91.          move.b  #'.',(a3)+
  92. mant     jsr     _LVOSPFlt(a6)
  93.          move.l  d0,d1
  94.          move.l  d7,d0
  95.          jsr     _LVOSPSub(a6)
  96.          move.l  d5,d1
  97.          jsr     _LVOSPMul(a6)
  98.          move.l  d0,d7
  99.          bsr.s   numeral
  100.          dbra    d4,mant
  101.  
  102. ; now write exponent
  103.  
  104.          move.b  #'E',(a3)+
  105.          tst.b   d6
  106.          bpl.s   none
  107.          move.b  #'-',(a3)+
  108.          neg.b   d6
  109. none     cmp.b   #10,d6
  110.          blt.s   nofirst
  111.          moveq   #0,d1
  112. flop     subi.b  #10,d6
  113.          addq.b  #1,d1
  114.          cmp.b   #10,d6
  115.          bge.s   flop
  116.          bsr.s   num1
  117. nofirst  move.b  d6,d1
  118.          bsr.s   num1
  119.          clr.b   (a3)
  120.  
  121. exit     move.l  a6,d1
  122.          beq.s   noFfp
  123.          move.l  _AbsExecBase,a6      close mathffp library
  124.          movea.l d1,a1
  125.          jsr     _LVOCloseLibrary(a6)
  126. noFfp    movea.l a3,a0
  127.          movem.l (a7)+,d4-d7/a1/a3/a6
  128.          rts
  129.  
  130. numeral  jsr     _LVOSPFix(a6)
  131.          move.b  d0,d1
  132. num1     addi.b  #'0',d1
  133.          move.b  d1,(a3)+
  134.          rts
  135.  
  136. FfpName  dc.b 'mathffp.library',0
  137.          even
  138.          end
  139.