Category : Assembly Language Source Code
Archive   : ASM-SUBR.ZIP
Filename : DEC16OUT

 
Output of file : DEC16OUT contained in archive : ASM-SUBR.ZIP

;-------------------------dec16out routine begins--------------------------+
; from BLUEBOOK OF ASSEMBLY ROUTINES FOR IBM PC & XT.
; page : 61
;
; NAME DEC16OUT
; ROUTINE FOR Conversion from 16-bit Binary to ASCII decimal
;
; FUNCTION: This routine accepts a 16-bit binary number in the DX register
; and converts it to ASCII decimal form which is sent to the std input
; device.
;
; INPUT: Upon entry an 16-bit binary number is in DX
; OUTPUT: A string of ASCII digits representing a decimal number is
; stored in a buffer called TBUFF and then sent out through the std output
; device.
; REGISTERS USED: No registers are modified. DX is used for input.
; SEGMENTS REFERENCED: DATAS is a data segment which contains TBUFF.
; ROUTINES CALLED: STDOUT
; SPECIAL NOTES: None
;
; ROUTINE TO CONVERT FROM INTERNAL 16-BIT BINARY TO ASCII DECIMAL.
;
dec16out proc far
;
push ds ; save registers
push di
push dx
push cx
push ax
;
mov ax,datas ; point to the data segment
mov ds,ax

;
; binary number is in DX
;
; Put the digits in a buffer
;
mov cx,0 ; initialize a counter
lea di, tbuff ; point to a buffer
;
dec16out1:
push cx ; save the count
mov ax,dx ; AX has the numerator
mov dx,0 ; clear upper half
mov cx,10 ; divisor of 10
div cx ; divide
xchg ax,dx ; get quotient
;
add al,30h ; increase to ASCII
mov [di],al ; put in tbuff
inc di ; point to next byte
;
pop cx ; restore count
inc cx ; count the digit
cmp dx,0 ; done ?
jnz dec16out1
;
; dump tbuff out
;
dec16out2
dec di ; back up through the tbuff
mov al,[di] ; get the byte from the tbuff
call stdout ; send it
loop dec16out2
;
pop ax ; restore registers
pop cx
pop dx
pop di
pop ds
ret ; return
;
dec16out endp
;-------------------------dec16out routine ends---------------------------+