/*
 * 5799-WZQ (C) COPYRIGHT IBM CORPORATION 1986
 * LICENSED MATERIALS - PROPERTY OF IBM
 * REFER TO COPYRIGHT INSTRUCTIONS FORM NUMBER G120-2083
 */
/* $Header:c19d.s 12.0$ */
/* $ACIS:c19d.s 12.0$ */
/* $Source: /ibm/acis/usr/src/lib/libc/ca/gen/RCS/c19d.s,v $ */

#include "LINKG.h"

	.data
rcsid:	.asciz	"$Header:c19d.s 12.0$"
	.text

 #       Convert 1-19 decimal digits to 2 unsigned longs, left justified
 #       int /*shiftcount*/ _c19d(twol,digitstring,count)
 
ENTRY(_c19d)
        stm	r10,REG_OFFSET+40(sp)

	lis	r10,0
	lis	r12,0
	lis	r0,0
	j	c1z

c1:	lcs	r0,0(r3)		#get next digit
	inc	r3,1
	nilz	r0,r0,0xf		#de-asciify it
	a	r12,r12			#multiply previous accumulation by 10:
	ae	r10,r10			#double,
	cas	r13,r12,r0
	cas	r11,r10,r0		#copy,
	a	r12,r12
	ae	r10,r10			#double twice more (8x),
	a	r12,r12
	ae	r10,r10
	a	r12,r13			#add in 2x, making 10x.
	ae	r10,r11
	a	r12,r0			#finally add in new digit
	aei	r10,r10,0
c1z:	sis	r4,1			#drop digit count
	jnm	c1			#is that all --

	lis	r0,0			#yes; prepare to normalize.
	cis	r10,0			
	jnz	c2
	cal	r0,0-64(r0)		#begin with a 32-bit shift
					#(r0 set to report 0 value)
	a	r10,r12			#copy low reg, set cc
	lis	r12,0
	jz	c4			#exit now if value is zero
	cal	r0,0-32(r0)		#fix the shift count; cc still set
c2:	jm	c4
c3:	a	r12,r12			#normalize 1 bit at a time
	ae	r10,r10
	bnmx	c3
	dec	r0,1
c4:	sts	r10,0(r2)		#store doubleword through
	sts	r12,4(r2)		#pointer argument

	lm	r10,REG_OFFSET+40(sp)
	brx	r15			#return, with shift as result
	cas	r2,r0,r0		

	TTNOFRM
