home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / dirs / a68kex_431.lzh / A68Kex / RealIn.asm < prev    next >
Assembly Source File  |  1991-01-17  |  4KB  |  194 lines

  1. *  RealIn change ASCII inputted real number
  2. *  to numeric real
  3. *
  4. *  IN
  5. *  a0 pointer to ASCII string
  6. *  OUT
  7. *  d0 real number
  8. *  d1 ok flag
  9. *  INTERNAL
  10. *  d2 sign of number
  11. *  d3 intermediate real
  12. *  d4 sign of exponent
  13. *  d5 value of exponent
  14. *
  15. * written by E. Lenz
  16. *            Johann-Fichte-Strasse 11
  17. *            8 Munich 40
  18. *            Germany
  19.  
  20. ***** exec *****
  21.  
  22. _AbsExecBase     equ 4
  23. _LVOCloseLibrary equ -$19e
  24. _LVOOpenLibrary  equ -$228
  25.  
  26. ****** mathffp ******
  27.  
  28. _LVOSPFlt        equ -$24
  29. _LVOSPNeg        equ -$3c
  30. _LVOSPAdd        equ -$42
  31. _LVOSPMul        equ -$4e
  32.  
  33. ten      equ  $a0000044
  34. tenth    equ  $cccccd3d
  35.  
  36.  
  37.          XDEF RealIn
  38.  
  39. RealIn   movem.l d2-d7/a1/a6,-(a7)     save used registers
  40.          move.l  #ten,d6
  41.          move.l  #tenth,d7
  42.          move.l  a0,-(a7)              save pointer to ASCII
  43.          move.l  _AbsExecBase,a6
  44.          lea     FfpName,a1            open mathffp library
  45.          moveq   #0,d0
  46.          jsr     _LVOOpenLibrary(a6)
  47.          move.l  (a7)+,a0
  48.          tst.l   d0
  49.          beq     bad
  50.          movea.l d0,a6
  51.  
  52.  
  53.          moveq   #0,d3             value zero
  54.          moveq   #0,d2             sign of number
  55.          moveq   #0,d4             sign of exponent
  56.          moveq   #0,d5             value of exponent
  57.  
  58.          bsr.s   sign
  59.  
  60. *  1st step convert until decimal point, e or blank
  61.  
  62. First    cmpi.b  #'.',(a0)       test end of step condition
  63.          beq.s   Point
  64.          bsr.s   chke
  65.          beq     Exp
  66.          bsr.s   chkex
  67.          beq     exit
  68.  
  69.          move.l  d6,d0         multiply result by 10
  70.          move.l  d3,d1
  71.          jsr     _LVOSPMul(a6)
  72.          move.l  d0,d3
  73.  
  74.          bsr     chk09
  75.          bpl     bad
  76.          jsr     _LVOSPFlt(a6)
  77.          move.l  d3,d1
  78.          jsr     _LVOSPAdd(a6)
  79.          move.l  d0,d3
  80.          bra.s   First
  81.  
  82. ; check if e or E
  83.  
  84. chke     cmpi.b  #'E',(a0)
  85.          beq.s   ise
  86.          cmpi.b  #'e',(a0)
  87. ise      rts
  88.  
  89. ; check end of input
  90.  
  91. chkex    cmpi.b  #' ',(a0)
  92.          beq.s   isex
  93.          cmpi.b  #$a,(a0)
  94. isex     rts
  95.  
  96. ; get sign
  97.  
  98. sign     cmpi.b  #'-',(a0)         get sign of number
  99.          bne.s   notm
  100.          move.b  (a0)+,d2
  101.          bra.s   return
  102. notm     cmpi.b  #'+',(a0)
  103.          bne.s   return
  104.          move.b  (a0)+,d0
  105. return   rts
  106.  
  107. ; step 2 convert decimal fraction
  108.  
  109. Point    move.b  (a0)+,d0      remove '.'
  110.          move.l  d7,d1         d1 as value of position
  111.  
  112. Second   bsr.s   chke         test end of step 2 condition
  113.          beq.s   Exp
  114.          bsr.s   chkex
  115.          beq.s   exit
  116.  
  117.          bsr.s   chk09
  118.          bpl.s   bad
  119.          move.l  d1,-(a7)
  120.          jsr     _LVOSPFlt(a6)
  121.          move.l  (a7),d1
  122.          jsr     _LVOSPMul(a6)
  123.  
  124.          move.l  d3,d1           add the numeral
  125.          jsr     _LVOSPAdd(a6)
  126.          move.l  d0,d3
  127.          move.l  (a7)+,d0
  128.  
  129.          move.l  d7,d1          decrement value of position
  130.          jsr     _LVOSPMul(a6)
  131.          move.l  d0,d1
  132.          bra.s   Second
  133.  
  134. Exp      move.b  (a0)+,d0      get rid of 'e'
  135.          exg     d2,d4
  136.          bsr.s   sign
  137.          exg     d2,d4         sign of exponent
  138.  
  139.          bsr.s   chk09         get exponent
  140.          bpl.s   bad
  141.          move.l  d0,d5
  142.          bsr.s   chk09
  143.          bpl.s   nosec
  144.          moveq   #10,d1
  145.          mulu    d1,d5
  146.          add.l   d0,d5
  147. nosec    tst.l   d5
  148.          beq.s   exit
  149.          move.l  d3,d0
  150.          move.l  d6,d1
  151.          subq.l  #1,d5
  152.          tst.l   d4
  153.          beq.s   plus
  154.          move.l  d7,d1
  155. plus     jsr     _LVOSPMul(a6)
  156.          dbra    d5,plus
  157.          move.l  d0,d3
  158.          bra.s   exit
  159.  
  160. bad      moveq   #1,d1
  161.          bra.s   noneg
  162.  
  163. ; check if decimal
  164.  
  165. chk09    moveq   #0,d0
  166.          move.b  (a0)+,d0
  167.          subi.b  #'0',d0
  168.          bmi.s   bad1
  169.          cmpi.b  #$a,d0
  170.          bge.s   bad1
  171.          rts
  172. bad1     moveq   #0,d0
  173.          rts
  174.  
  175. exit     move.l  d3,d0
  176.          tst.l   d2
  177.          beq.s   non
  178.          jsr     _LVOSPNeg(a6)
  179. non      moveq   #0,d1
  180.  
  181. noneg    movem.l d0-d1,-(a7)
  182.          move.l  a6,d1
  183.          beq.s   noFfp
  184.          move.l  _AbsExecBase,a6      close mathffp library
  185.          movea.l d1,a1
  186.          jsr     _LVOCloseLibrary(a6)
  187. noFfp    movem.l (a7)+,d0-d1
  188.          movem.l (a7)+,d2-d7/a1/a6
  189.          rts
  190.  
  191. FfpName  dc.b 'mathffp.library',0
  192.          even
  193.          end
  194.