home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frostbyte's 1980s DOS Shareware Collection
/
floppyshareware.zip
/
floppyshareware
/
GLEN
/
VOL10N22.ZIP
/
LTOA.ASM
< prev
next >
Wrap
Assembly Source File
|
1991-09-30
|
3KB
|
97 lines
title LTOA --- Convert long (32-bit) integer to ASCII string
page 55,132
; LTOA.ASM --- Convert long (32-bit) integer to ASCII string
;
; Copyright (C) 1989 Ray Duncan
;
; Call with: DX:AX = 32-bit integer
; DS:SI = buffer to receive string,
; must be at least 11 bytes long
; CX = radix
;
; Returns: DS:SI = address of converted string
; AX = length of string
;
; Destroys: BX, DX
;
; Since test for value = zero is made after a digit
; has been stored, the resulting string will always
; contain at least one significant digit.
_TEXT segment word public 'CODE'
assume cs:_TEXT
public ltoa
ltoa proc near
add si,11 ; advance to end of buffer
push si ; and save that address.
or dx,dx ; test sign of 32 bit value,
pushf ; and save sign on stack.
jns ltoa1 ; jump if value was positive.
not dx ; it was negative, take 2's
not ax ; complement of the value.
add ax,1
adc dx,0
ltoa1: call divide ; divide value by radix
add bl,'0' ; convert remainder to ASCII digit
cmp bl,'9' ; in case converting to hex ASCII,
jle ltoa2 ; jump if in range 0-9,
add bl,'A'-'9'-1 ; correct digit if in range A-F.
ltoa2: dec si ; back up through buffer
mov [si],bl ; store this character into string.
mov bx,ax ; is value = zero yet?
or bx,dx
jnz ltoa1 ; no, convert another digit.
popf ; was original value negative?
jns ltoa3 ; no, jump
dec si ; yes, store - sign into output
mov byte ptr [si],'-'
ltoa3: pop ax ; calculate length of string
sub ax,si
ret ; back to caller.
ltoa endp
;
; General purpose 32 bit by 16 bit unsigned divide. This routine must
; be used instead of the machine's usual unsigned divide for cases
; where the quotient may overflow 16 bits (for example, 100,000 / 2 ).
; If called with a zero divisor, this routine returns the dividend
; unchanged and gives no warning.
;
; Call with: DX:AX = 32 bit dividend
; CX = divisor
;
; Returns: DX:AX = quotient
; BX = remainder
; CX = divisor (unchanged)
;
; Destroys: Nothing
;
divide proc near
jcxz div1 ; exit if divide by zero
push ax ; 0:dividend_hi/divisor
mov ax,dx
xor dx,dx
div cx
mov bx,ax ; BX = quotient1
pop ax ; remainder1:dividend_lo/divisor
div cx
xchg bx,dx ; DX:AX = quotient1:quotient2
div1: ret ; BX = remainder2
divide endp
_TEXT ends
end