;-------------------------i162bcd routine begins--------------------------+
; from BLUEBOOK OF ASSEMBLY ROUTINES FOR IBM PC & XT.
;         page : 70
;
; NAME I162BCD
; ROUTINE FOR CONVERSION FROM 16-BIT BINARY TO BCD
;
; FUNCTION: This routine converts from internal 16-bit binary numbers to
; numbers stored in internal BCD format
;
; INPUT: Upon entry a 16-bit binary number is in the DX register
;
; OUTPUT: Upon return a 36-digit number is stored in BCD form in an 18-
; byte buffer in the data segment called BCDBUFF
;
; REGISTERS USED:  No registers are modified.  DX is used for input.
;
; SEGMENTS REFERENCED:  DATAS is a data segment which contains the buffer
; BDCBUFF
;
; ROUTINES CALLED:  None
; SPECIAL NOTES: None
;
; ROUTIINE TO CONVERT FROM INTERNAL 16-BIT BINARY TO INTERNAL BCD
;
i162bcd	proc	far
;
	push	ds		; save registers
	push	si
	push	dx
	push	cx
	push	ax
;
; set up the data segment
	mov	ax,datas	; point to data segment
 	mov	ds,ax
;
; a binary number is in DX
;
; clear bcd buffer
	lea	di,bcdbuff	; point to buffer
	mov	al,0		; zero byte
	mov	cx,18		; bcdbuff size
;
i162bcd1:
	mov	[di],al		; clear byte
	inc	di		; point to next one
	loop	i162bcd1
;
; put the digits in a buffer
	lea	di,bcdbuff	; point to bcdbuff
;
i162bcd2
	mov	ax,dx		; numerator
	mov	dx,0		; clear upper half
	mov	cx,10		; divisor of 10
	div	cx		; divide
	xchg	ax,dx		; get quotient
	mov	bl,al		; save digit
;
	mov	ax,dx		; numerator
	mov	dx,0		; clear upper half
	mov	cx,10		; divisor of 10
	div	cx		; divide
	xchg	ax,dx		; get quotient
;
	mov	cl,4		; for a count of 4
	rol	al,cl		; rotate byte
	and	al,0Fh		; just the digit
	or	al,bl		; combine digits
;
	mov	[di],al		; put in buffer
	inc	di		; next byte
	cmp	dx,0		; done ?
	jnz	i162bcd2	; nope
;
	pop	ax		; yes, done...restore registers
	pop	cx
	pop	dx
	pop	di
	pop	ds
	ret			; return
;
i162bcd	endp
;-------------------------i162bcd routine ends---------------------------+
