/
/ Ascii to integer.
/

	.globl	atoi

/
/ int atoi(p);
/ char *p;
/ Convert string to integer.
/ No checking.
/

atoi:	jsr	r0,__csav	/ Linkage

	mov	12(r5),r4	/ r4 = ptr to string
	clr	r3		/ r3 = number
	clr	r2		/ r2 = sign flag

0:	movb	(r4)+,r0	/ Grab byte
	beq	1f		/ Done
	cmp	r0,$'\n		/ Ignore newlines
	beq	0b		/
	cmp	r0,$'\t		/ Tabs
	beq	0b		/
	cmp	r0,$'+		/ Plus signs
	beq	0b		/
	cmp	r0,$' 		/ And spaces
	beq	0b		/

	cmp	r0,$'-		/ If `-' sign
	bne	0f		/ then
	inc	r2		/ set flag
	br	0b		/ and ignore it.

0:	sub	$'0,r0		/ Convert to int
	cmp	r0,$9		/ Legal ?
	bhi	0f		/ No, done
	asl	r3		/ r3 = 10*r3
	mov	r3,r1		/
	asl	r3		/
	asl	r3		/
	add	r1,r3		/
	add	r0,r3		/ r3 = r3 + new
	movb	(r4)+,r0	/ Get next
	bne	0b		/ Br if not end

0:	asr	r2		/ Need to negate
	bcc	1f		/ No
	neg	r3		/ Do it !!

1:	mov	r3,r0		/ Return to caller
	jmp	__cret		/
