home *** CD-ROM | disk | FTP | other *** search
- * :ts=8
- *
- * A very simple function which simply converts an ASCII string to its numeric
- * equivalent. It is MUCH smaller than it's equivalent in the Lattice
- * library.
- *
-
- xdef atoi
-
- csect text,0,0,1,2
-
- atoi:
- moveq #0,d0 ; Initialise integer to 0
- moveq #0,d1 ; Initialise temporary variable
- move.l 4(a7),a0 ; Get pointer to string
- loop:
- move.b (a0)+,d1 ; Get next character from string
- subi.b #$30,d1 ; Convert to range 0-9
- cmpi.b #10,d1 ; If outside range,
- bhi.s exit ; then return to caller
- mulu #10,d0 ; Update count
- add.l d1,d0 ; Add in new digit
- bra.s loop ; And go back for next digit
- exit:
- rts ; Return with number in D0
-
- end
-