;-------------------------bcd2i16 routine begins--------------------------+
; from BLUEBOOK OF ASSEMBLY ROUTINES FOR IBM PC & XT.
;         page : 68
;
; NAME BCD2I16
; ROUTINE FOR converting internal BCD format to internal 16-bit binary
;
; FUNCTION: This routine converts from internal BCD format to internal
; binary format.
;
; INPUT: Upon entry a 36-digit number is contained in an 18-digit BCD
; buffer called BCDBUFF.
;
; OUTPUT: A 16-bit binary number is returned in DX
;
; REGISTERS USED:  Only DX is modified.  DX is used for output.
;
; SEGMENTS REFERENCED:  DATAS is a data segment which contains the buffer
; BDCBUFF
;
; ROUTINES CALLED:  None
; SPECIAL NOTES: None
;
; ROUTIINE TO CONVERT FROM INTERNAL BCD TO INTERNAL 16-BIT BINARY
;
bcd2i16	proc	far
;
	push	ds		; save registers
	push	si
	push	cx
	push	ax
;
; set up the data segment
	mov	ax,datas	; point to data segment
 	mov	ds,ax
;
; set up a loop
	mov	cx,18		; initialize counter
	lea	si,bcdbuff	; point to buffer
	add	si,17		; point to end of bcdbuff
	mov	dx,0		; init DX to 0
;
bcd2i161:
	push	cx		; save loop count
	mov	al,[si]		; get BCD byte
	dec	si		; point to next one
	mov	bl,al		; save it
;
; upper digit
	mov	cl,4		; for a count of 4
	rol	al,cl		; rotate byte
	and	al,0Fh		; just the digit
	cbw			; convert to word
;
	push	ax		; save the digit
	mov	ax,dx
	mov	cx,10		; multiplier of 10
	mul	cx		; multiply
	mov	dx,ax		; result in dx
	pop	ax		; restore digit
;
	add	dx,ax		; add in digit
;
	moov	al,bl		; byte back
;
; lower digit
	and 	al,0Fh		; just the digit
	cbw			; convert to word
;
	push	ax		; save digit
	mov	ax,dx
	mov	cx,10		; multiplier of 10
	mul	cx		; multiply
	mov	dx,ax		; result in DX
	pop	ax		; restore digit
;
	add	dx,ax		; add in digit
;
	pop	cx		; restore loop count
	loop	bcd2i161
;
	pop	ax		; restore registers
	pop	cx
	pop	si
	pop	ds
	ret			; return
;
bcd2i16	endp
;-------------------------bcd2i16 routine ends---------------------------+
