	page	,132
	title	Print packed bcd number
code	segment public
	assume	cs:code,ds:code,es:code
	public	print_bcd

print_buffer	db	19 dup(?)
		db	10,13,'$'

print_bcd	proc	near
	push	cx
	push	dx		; save registers
	push	di
	push	es
	push	si
	push	ds
	push	cs
	pop	es		; set es to code segment
	cld			; forward
	mov	di,offset print_buffer	; point at print buffer
	mov	cx,19
	mov	al,' '
	push	di
	rep	stosb		; fill area with blanks
	pop	di
	inc	di		; point to first number position
	mov	cx,9		; 9 bytes to display
	add	si,cx		; point at last byte of packed bcd
	cmp	byte ptr [si],0 ; test for plus or minus
	je	fill_loop	; nothing to put there
	mov	byte ptr es:[di-1],'-'    ; put in the minus sign
fill_loop:
	dec	si		; point to next packed bcd
	mov	al,[si] 	; get the number
	mov	ah,al		; into both
	and	al,0f0h 	; isolate high bits
	shr	al,1
	shr	al,1
	shr	al,1
	shr	al,1
	or	al,030h 	; turn into ascii number
	and	ah,00fh 	; get low nybble
	or	ah,030h 	; turn into ascii
	stosw			; store the numbers
	loop	fill_loop

;----- number exists in data area

	mov	si,offset print_buffer+1
	push	cs
	pop	ds		; address into buffer
blank_leading:
	cmp	byte ptr [si],'0'       ; is it leading zero?
	jne	set_sign	; no, put the sign in before this number
	mov	byte ptr[si],' '; blank leading zero
	inc	si
	jmp	blank_leading
set_sign:
	mov	ah,print_buffer ; get the current sign
	mov	print_buffer,' '; blank it out
	mov	[si-1],ah	; put the sign in front of the number

print_string:
	mov	dx,offset print_buffer
	mov	ah,9
	int	21h		; print the string
	pop	ds
	pop	si
	pop	es
	pop	di
	pop	dx
	pop	cx
	ret			; return from here
print_bcd	endp
code	ends
	end

