home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / C / MAXONC3_6OF8.DMS / in.adf / LIBSRC.LHA / LIBSRC / strtoint.asm < prev    next >
Encoding:
Assembly Source File  |  1994-04-16  |  3.8 KB  |  239 lines

  1.  
  2. *    Maxon C++:
  3. *
  4. *    Library-Modul "strtoint.o"
  5. *
  6. *    Jens Gelhar 06.11.91
  7. *
  8. *    All rights reversed - warranty void
  9.  
  10.     xdef    _strtovl,strtovl__PCcPPci
  11.     xdef    _strtouvl,strtouvl__PCcPPci
  12.     xdef    _strtol,strtol__PCcPPci
  13.     xdef    _strtoul,strtoul__PCcPPci
  14.     xdef    _atol,atol__PCc
  15.     xdef    _atoi,atoi__PCc
  16.     xdef    _uintmult
  17.  
  18.     xref    _errno
  19.  
  20. _atol:
  21. atol__PCc:
  22. _atoi:
  23. atoi__PCc:    move.l d1,-(a7)
  24.     pea 10.w
  25.     clr.l -(a7)
  26.     move.l 8+8(a7),-(a7)
  27.     bsr _strtovl
  28. atoiin    lea 12(a7),a7
  29.     tst.l d1
  30.     bmi.b minus
  31.     bne.b overflow
  32.     tst.l d0
  33.     bpl.b atoiok
  34. overflow
  35.     move.l #$7FFFFFFF,d0
  36.     bra.b atoiok
  37. minus    addq.l #1,d1
  38.     bne.b underflow
  39.     tst.l d0
  40.     bmi.b atoiok
  41. underflow
  42.     move.l #$80000000,d0
  43. atoiok    move.l (a7)+,d1
  44.     rts
  45.  
  46. _strtol:
  47. strtol__PCcPPci:
  48.     move.l d1,-(a7)
  49.     move.l 8+8(a7),-(a7)            ; Parameter kopieren
  50.     move.l 8+8(a7),-(a7)
  51.     move.l 8+8(a7),-(a7)
  52.     bsr.b _strtovl
  53.     bra.b atoiin
  54.  
  55. _strtoul:
  56. strtoul__PCcPPci:
  57.     move.l d1,-(a7)
  58.     move.l 8+8(a7),-(a7)            ; Parameter kopieren
  59.     move.l 8+8(a7),-(a7)
  60.     move.l 8+8(a7),-(a7)
  61.     bsr.b _strtouvl
  62.     lea 12(a7),a7
  63.     tst.l d1
  64.     beq.b stul1
  65.     moveq #-1,d0
  66. stul1:    move.l (a7)+,d1
  67.     rts
  68.  
  69. _strtouvl:
  70. strtouvl__PCcPPci:
  71.     movem.l d2-d4/a0,-(a7)
  72.     move.l 4*4+4(a7),a0     ; Zeiger auf Zeichenkette
  73.     bsr Overread
  74.     tst.b d2
  75.     beq warnix
  76.     move.l 4*4+12(a7),d4
  77.     cmp.b #'+',d2
  78.     bne.b ulconv
  79.     move.b (a0)+,d2
  80. ulconv    bsr.b Convert
  81.     bra End
  82.  
  83. _strtovl:
  84. strtovl__PCcPPci:    ; Stack-Parameter: char*, char**, int base
  85.     movem.l d2-d4/a0,-(a7)
  86.     move.l 4*4+4(a7),a0     ; Zeiger auf Zeichenkette
  87.     bsr Overread
  88.     tst.b d2
  89.     beq warnix
  90.     move.l 4*4+12(a7),d4    ; Basis?
  91.     cmp.b #'-',d2
  92.     bne.b positiv
  93.     move.b (a0)+,d2
  94.     beq warnix
  95.     ; Zahl mit "-":
  96.     bsr.b Convert
  97.     tst.l d1
  98.     bpl.b negativ
  99.     moveq #0,d0
  100.     move.l #$80000000,d1
  101.     bra ERanEnd
  102. negativ    not.l d0
  103.     not.l d1
  104.     addq.l #1,d0
  105.     bhs End
  106.     addq.l #1,d1
  107.     bra ERanEnd
  108.  
  109. positiv    cmp.b #'+',d2
  110.     bne.b posit1
  111.     move.b (a0)+,d2
  112.     beq warnix
  113. posit1    bsr.b Convert
  114.     tst.l d1
  115.     bpl End
  116.     moveq #-1,d0
  117.     move.l #$7FFFFFFF,d1
  118.     bra ERanEnd
  119.  
  120. Convert:
  121.     ; String a0, erste Ziffer d2, Basis-Parameter d4
  122.     moveq #0,d0
  123.     moveq #0,d1
  124.     cmp.w #2,d4
  125.     blo.b whichbase
  126.     cmp.w #36,d4
  127.     blo.b isitanumber
  128. whichbase
  129.     ; ersma' Basis feststellen:
  130.     cmp.b #'0',d2
  131.     bne.b decimal
  132.     move.b (a0)+,d2
  133.     moveq #8,d4
  134.     cmp.b #'x',d2
  135.     beq.b Hex
  136.     cmp.b #'X',d2
  137.     bne.b thisbase
  138. Hex    move.b (a0)+,d2
  139.     moveq #16,d4
  140.     bra.b isitanumber
  141. decimal    blo.b mumpitz
  142.     cmp.b #'9',d2
  143.     bhi.b mumpitz
  144.     moveq #10,d4
  145. isitanumber:    ; d2 wäre erste Ziffer - aber ist es eine?
  146.     bsr.b whichdigit
  147.     cmp.w d4,d3
  148.     bhs.b mumpitz
  149. thisbase
  150.     bsr.b whichdigit
  151.     cmp.w d4,d3
  152.     bhs.b convEnde
  153.     move.l d3,-(a7)
  154.     move.l d4,d2
  155.     moveq #0,d3
  156.     bsr _uintmult
  157.     add.l (a7)+,d0
  158.     bhs.b nocarry
  159.     addq.l #1,d1
  160. nocarry    move.b (a0)+,d2
  161.     bne.b thisbase
  162. convEnde
  163.     rts
  164. mumpitz    ; Zahl ohne Ziffer!
  165.     move.l #1001,_errno
  166.     rts
  167.  
  168. whichdigit:    ; d2.b in Ziffer wandeln (nach d3)
  169.     moveq #0,d3
  170.     move.b d2,d3
  171.     sub.b #'0',d3
  172.     blo.b nodigitatall
  173.     cmp.w #9,d3
  174.     bls.b adigit
  175.     subq.w #'A'-'0'-10,d3
  176.     cmp.w #10,d3
  177.     blo.b nodigitatall
  178.     cmp.w #36,d3
  179.     blo.b adigit
  180.     sub.w #'a'-'A',d3
  181.     cmp.w #10,d3
  182.     blo.b nodigitatall
  183.     cmp.w #36,d3
  184.     blo.b adigit
  185. nodigitatall    moveq #-1,d3
  186. adigit    rts
  187.  
  188. warnix:    ; keine Zahl da!
  189.     move.l #1001,_errno
  190.     moveq #0,d0
  191.     moveq #0,d1
  192.     bra.b End
  193. ERanEnd    move.l #1000,_errno
  194. End
  195.     move.l 4*4+8(a7),d2
  196.     beq.b ret
  197.     subq.l #1,a0
  198.     exg d2,a0               ; Zeiger auf Rest
  199.     move.l d2,(a0)
  200. ret    movem.l (a7)+,d2-d4/a0
  201.     rts
  202.  
  203. Overread:    ; Spaces etc. überlesen, erstes Zeichen nach d2
  204.     move.b (a0)+,d2
  205.     beq.b ovrret
  206.     cmp.b #' ',d2
  207.     bls.b Overread
  208. ovrret    rts
  209.  
  210. _uintmult:    ; d0|d1 *= d2|d3, d7 = überlauf-flag
  211.     movem.l d4-d7,-(a7)
  212.     move.l d0,d4
  213.     move.l d1,d5
  214.     moveq #63,d6    ; Zähler
  215.     moveq #0,d0
  216.     moveq #0,d1
  217.     moveq #0,d7
  218. multLoop    asl.l #1,d0
  219.     roxl.l #1,d1
  220.     blo.b multOvr
  221.     asl.l #1,d2
  222.     roxl.l #1,d3
  223.     bhs.b multNext
  224.     add.l d5,d1
  225.     blo.b multOvr
  226.     add.l d4,d0
  227.     bhs.b multNext
  228.     addq.l #1,d1
  229.     blo.b multOvr
  230. multNext dbra d6,multLoop
  231. multRet    movem.l (a7)+,d4-d7
  232.     rts
  233. multOvr    moveq #-1,d0
  234.     moveq #-1,d1
  235.     move.l #1000,_errno
  236.     bra.b multRet
  237.  
  238.     end
  239.