Category : Assembly Language Source Code
Archive   : ASM_SUBR.ZIP
Filename : I162BCD

 
Output of file : I162BCD contained in archive : ASM_SUBR.ZIP
;-------------------------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---------------------------+


  3 Responses to “Category : Assembly Language Source Code
Archive   : ASM_SUBR.ZIP
Filename : I162BCD

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/