/
/ Ascii to long.
/

	.globl	atol

/
/ long atol(*s);
/ char *s;
/ Convert ascii string to a long
/ int.
/

atol:	jsr	r0,__csav	/ Linkage

	mov	12(r5),r4	/ r4 = ptr to string
	clr	r3		/ r3 = sign flag
	clr	r1		/ r1 = low
	clr	r0		/ r0 = high

0:	movb	(r4)+,r2	/ Grab character.
	beq	1f		/ Done
	cmp	r2,$'\t		/ Ignore tabs
	beq	0b		/
	cmp	r2,$'\n		/ Newlines
	beq	0b		/
	cmp	r2,$'+		/ `+' signs
	beq	0b		/
	cmp	r2,$' 		/ and spaces
	beq	0b		/

	cmp	r2,$'-		/ If `-'
	bne	0f		/ then
	inc	r3		/ hit sign flag and
	br	0b		/ ignore

0:	sub	$'0,r2		/ Make int
	cmp	r2,$9		/ Legal ?
	bhi	0f		/ No
	asl	r1		/ r[01] = 10*r[01]
	rol	r0		/
	mov	r0,-(sp)	/ Harunph.
	mov	r1,-(sp)	/
	asl	r1		/
	rol	r0		/
	asl	r1		/
	rol	r0		/
	add	(sp)+,r1	/ Add in the rest
	adc	r0		/
	add	(sp)+,r0	/
	add	r2,r1		/ Add in new digit
	adc	r0		/
	movb	(r4)+,r2	/ Get next
	bne	0b		/ Loop if not the end

0:	asr	r3		/ `-' ?
	bcc	1f		/ Nope
	neg	r0		/ Negate
	neg	r1		/
	sbc	r0		/

1:	jmp	__cret		/ Done
