	.even
/double precision ASCII to integer subroutine
/inputs:
/       "digitptr" pts to beginning of ASCII string
/outputs:
/      high order result returned to (r5)
/      low order result returned to 2(r5)
atoi:
	clr	-(sp)			/keeps track of no. digits
	mov	r2,-(sp)		/save regs
	mov	r3,-(sp)
	clr	r3
1:
	jsr	r5,getdigit
	sub	$'0,r0
	cmp	r0,$9.
	bhi	1f
	inc	4(sp)			/inc no. of digits
	cmp	4(sp),$5		/only 5 digits accepted
	bgt	1f
	mov	r3,mq
	mov	$10.,mul
	mov	ac,r2
	mov	mq,r3
	add	r0,r3
	adc	r2
	br	1b
1:
	add	$'0,r0			/add to preserve 1st non-digit
	mov	r2,(r5)+
	mov	r3,(r5)+
	mov	(sp)+,r3		/restore regs
	mov	(sp)+,r2
	tst	(sp)+
	rts	r5



/double precision integer to ASCII subroutine
/inputs:
/      (r5) pts to address of double precision binary integer
/outputs:
/      ASCII number to print file
itoa:
	mov	(r5)+,r0
	tst	(r0)+			/add 2 to r0
	mov	(r0),mq			/get low order 16 bits
	mov	-(r0),ac		/get high order 16 bits
	jsr	pc,itoa1
	rts	r5
itoa1:
	mov	$10.,div		/divide by 10.
	mov	ac,-(sp)		/move remainder onto stack
	tst	mq
	beq	1f			/branch if 0 quotient
	clr	ac			/clear ac for next divide
	jsr	pc,itoa1
1:
	add	$'0,(sp)
	movb	(sp)+,digit
	mov	$1,r0
	sys	write; digit; 1		/write single digit
	rts	pc

getdigit:
	movb	*digitptr,r0		/char rt-adjusted
	inc	digitptr
	rts	r5

digitptr:
	0
digit:
	.=.+1
