	model	large extend_text,pascal
	include	extend.inc

	extrn	ExtMul:far,Comp2Ext:far,ExtPow10:far

	.data

C1e8	dt	1e8

	.code	Extend_Text

	Argm	Src,dword,1
	Argm	Dst,dword,1
	Loc	Temp,word,4
	Loc	J,word,1
	Loc	I,word,1
	Entry	Str2Ext
	push	si di
	push	ds
	lds	si,Src
	cld
	xor	di,di
	mov	dx,di
	mov	cx,di
	mov	bx,di
	mov	I,di
	mov	J,di
@@1:	lodsb
	cmp	al,'0'
	jb	@@6
	cmp	al,'9'
	ja	@@6
	sub	al,'0'
	cbw
	or	bx,bx
	jnz	@@3
	or	cx,cx
	jnz	@@4
	or	dx,dx
	jnz	@@4
	xchg	ax,di
	mov	dx,10
	mul	dx
@@2:	add	di,ax
	adc	dx,0
	adc	cx,0
	adc	bx,0
	mov	ax,J
	add	I,ax
	jmp	@@1
@@3:	cmp	bx,3276
	jae	@@5
@@4:	push	ax
	shl	di,1
	rcl	dx,1
	rcl	cx,1
	rcl	bx,1
	push	bx cx dx di
	shl	di,1
	rcl	dx,1
	rcl	cx,1
	rcl	bx,1
	shl	di,1
	rcl	dx,1
	rcl	cx,1
	rcl	bx,1
	pop	ax
	add	di,ax
	pop	ax
	adc	dx,ax
	pop	ax
	adc	cx,ax
	pop	ax
	adc	bx,ax
	pop	ax
	jmp	@@2
@@5:	mov	ax,J
	inc	ax
	add	I,ax
	jmp	@@1
@@6:	cmp	al,'.'
	jne	@@7
	cmp	J,0
	jne	@@7
	dec	J
	jmp	@@1
@@7:	mov	Temp[0],di
	mov	Temp[2],dx
	mov	Temp[4],cx
	mov	Temp[6],bx
	mov	di,I
	cmp	al,'E'
	je	@@8
	cmp	al,'e'
	jne	@@13
@@8:	xor	bx,bx
	lodsb
	mov	cl,al
	cmp	al,'-'
	je	@@10
	cmp	al,'+'
	je	@@10
@@9:	cmp	al,'0'
	jb	@@11
	cmp	al,'9'
	ja	@@11
	cmp	bx,1000
	jae	@@11
	sub	al,'0'
	cbw
	shl	bx,1
	mov	dx,bx
	shl	bx,1
	shl	bx,1
	add	bx,dx
	add	bx,ax
@@10:	lodsb
	jmp	@@9
@@11:	cmp	cl,'-'
	jne	@@12
	neg	bx
@@12:	add	di,bx
@@13:	pop	ds
	lea	ax,Temp
	push	ss ax
	les	ax,Dst
	push	es ax
	call	Comp2Ext
	mov	ax,0f000h
	cmp	di,ax
	jge	@@14
	sub	di,ax
	push	ax
	les	ax,Dst
	push	es ax
	call	ExtPow10
@@14:	push	di
	les	ax,Dst
	push	es ax
	call	ExtPow10
	xchg	ax,si
	dec	ax
	sub	ax,Src.Offs
	jmp	short @@15
@@15:	pop	di si
	Exit

	Argm	Src,dword,1
	Argm	W,word,1
	Argm	Sign,dword,1
	Argm	Dst,dword,1
	Loc	Temp,word,5
	Loc	P,dword,1
	Loc	SSP,word,1
	Loc	J,word,1
	Loc	I,word,1
	Entry	Ext2Str
	push	si di
	mov	ax,8000h
	cmp	W,0
	jg	@@1
	mov	ax,18
	xchg	ax,W
@@1:	mov	j,ax
	les	di,dst
	mov	P.Offs,di
	mov	P.Segm,es
	push	ds
	lds	si,Src
	lea	di,Temp
	push	ss
	pop	es
	cld
	mov	cx,5
	rep	movsw
	pop	ds
	mov	ax,Temp[8]
	sub	cx,cx
	shl	ax,1
	rcl	cx,1
	les	di,Sign
	mov	es:[di],cx
	shr	ax,1
	jz	@@2
	cmp	ax,7fffh
	jb	@@4
	mov	dx,7fffh
	jmp	short @@3
@@2:	sub	dx,dx
@@3:	les	di,Dst
	sub	al,al
	stosb
	mov	ax,dx
	jmp	@@27
@@4:	sub	ax,3fffh
	cmp	ax,27
	jge	@@5
	or	ax,ax
	jl	@@5
	mov	I,8
	jmp	@@7
@@5:	mov	dx,4d10h
	imul	dx
	xchg	ax,bx
	mov	ah,4dh
	mov	al,byte ptr Temp[7]
	shl	al,1
	mul	ah
	add	ax,bx
	adc	dx,0
	neg	ax
	adc	dx,0
	mov	I,dx
	cmp	dx,J
	jl	@@2
	mov	si,8
	sub	si,dx
	mov	ax,1000h
	cmp	si,ax
	jl	@@6
	sub	si,ax
	push	ax
	lea	ax,Temp
	push	ss ax
	call	ExtPow10
@@6:	push	si
	lea	ax,Temp
	push	ss ax
	call	ExtPow10
@@7:	mov	SSP,sp
@@8:	mov	cx,30
	sub	cl,byte ptr Temp[8]
	sub	bx,bx
	mov	si,Temp[0]
	mov	di,Temp[2]
	mov	ax,Temp[4]
	mov	dx,Temp[6]
	cmp	cx,16
	jb	@@9
	mov	bx,si
	mov	si,di
	mov	di,ax
	mov	ax,dx
	sub	dx,dx
	sub	cx,16
	jz	@@11
@@9:	push	bp
	sub	bp,bp
@@10:	shr	dx,1
	rcr	ax,1
	rcr	di,1
	rcr	si,1
	rcr	bx,1
	rcr	bp,1
	loop	@@10
	mov	cx,bp
	pop	bp
@@11:	push	di
	lea	di,Temp
	push	ss
	pop	es
	xchg	ax,cx
	stosw
	xchg	ax,bx
	stosw
	xchg	ax,si
	stosw
	pop	ax
	stosw
	mov	ax,3ffeh
	stosw
	xchg	ax,cx
@@12:	mov	bx,I
	les	di,P
	mov	si,Dst.Offs
	mov	cx,10000
	div	cx
	mov	cx,100*256+10
	xchg	ax,dx
	div	ch
	xchg	ax,dx
	div	ch
	cmp	al,ch
	jb	@@13
	sub	al,ch
	inc	bx
	push	ax
	mov	al,'1'
	call	@19
	pop	ax
@@13:	call	@15
	mov	I,bx
	mov	P.Offs,di
	lea	ax,Temp
	push	ss ax
	cmp	byte ptr Temp[7],0
	js	@@14
	push	ss ax ss ax
	call	Comp2Ext
	sub	Temp[8],64
@@14:	lea	ax,C1e8
	push	ds ax
	call	ExtMul
	sub	ax,ax
	mov	dx,ax
	cmp	Temp[8],3fffh
	jb	@@12
	jmp	@@8
@15	proc	near
	call	@@16
	xchg	ax,dx
@@16:	mov	ch,ah
	call	@@17
	mov	al,ch
@@17:	cbw
	div	cl
	add	ax,'00'
	call	@@18
	mov	al,ah
@@18:	cmp	al,'0'
	jne	@19
	cmp	di,si
	je	@@20
@19:	stosb
	dec	W
	jl	@22
@@20:	cmp	bx,J
	jle	@22
	dec	bx
	ret
@15	endp
@@21:	jmp	@@2
@22:	mov	sp,SSP
	cmp	di,si
	je	@@21
	dec	di
	add	bx,di
	sub	bx,si
	cmp	byte ptr es:[di],'5'
	jae	@@25
@@23:	cmp	di,si
	je	@@21
	dec	di
	cmp	byte ptr es:[di],'0'
	je	@@23
	jmp	short @@26
@@24:	dec	di
	inc	byte ptr es:[di]
	cmp	byte ptr es:[di],'9'
	jbe	@@26
@@25:	cmp	di,si
	jne	@@24
	mov	byte ptr es:[di],'1'
	inc	bx
@@26:	mov	byte ptr es:[di+1],0
	mov	ax,bx
	jmp	short @@27
@@27:	pop	di si
	Exit

	end
