home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 2: PC / frozenfish_august_1995.bin / bbs / d02xx / d0216.lha / BackDrop / src / atoi.a next >
Text File  |  1989-06-02  |  669b  |  28 lines

  1. * :ts=8
  2. *
  3. * A very simple function which simply converts an ASCII string to its numeric
  4. * equivalent. It is MUCH smaller than it's equivalent in the Lattice
  5. * library.
  6. *
  7.  
  8.     xdef    atoi
  9.  
  10.     csect   text,0,0,1,2
  11.  
  12. atoi:
  13.     moveq    #0,d0            ; Initialise integer to 0
  14.     moveq    #0,d1            ; Initialise temporary variable
  15.     move.l    4(a7),a0        ; Get pointer to string
  16. loop:
  17.     move.b    (a0)+,d1        ; Get next character from string
  18.     subi.b    #$30,d1            ; Convert to range 0-9
  19.     cmpi.b    #10,d1            ; If outside range,
  20.     bhi.s    exit            ; then return to caller
  21.     mulu    #10,d0            ; Update count
  22.     add.l    d1,d0            ; Add in new digit
  23.     bra.s    loop            ; And go back for next digit
  24. exit:
  25.     rts                ; Return with number in D0
  26.  
  27.     end
  28.