A conversion of Masm32 library function "dwtoa" for 64 bit.
The original (dwtoa) can be found in \masm32\m32lib\dwtoa.asm.
; ---------------------------------------------------------------
; credts: Tim Roberts, Jibz for 'dwtoa', hutch for masm32.lib
; ---------------------------------------------------------------
; Converted for 64 bit usage by zedd151 - tweaked by sinsi
; ---------------------------------------------------------------
; convert signed qword to ascii decimal string
; qwValue is value to be converted
; lpBuffer is the address of the receiving buffer
; EXAMPLE:
; invoke qwtoa, <signed qword>, addr buffer
; ---------------------------------------------------------------
qwtoa proc qwValue:qword, lpBuffer:qword
mov rax,rcx
mov r8,rcx
mov r9,rdx
push 0
test rax,rax
jnz not_zero
push "0"
jmp reverse ;<<<<<<<<<<<<<<<<<<<<
not_zero:
jns pos
neg rax
pos:
mov rcx, 0CCCCCCCCCCCCCCCDh
digit:
mov r10, rax
mul rcx
shr rdx, 3
mov rax, rdx
lea rdx, [rdx*4+rdx]
add rdx, rdx
sub r10, rdx
add r10b,"0"
push r10
test rax,rax
jnz digit
test r8,r8
jns reverse
push "-"
reverse:
pop rax
mov [r9],al
inc r9
test al,al
jnz reverse
dtaexit:
ret
qwtoa endp
Thank you sinsi for your assistance. :thumbsup:
Nasty little bug if qwValue=0 :sad:
test rax,rax
jnz not_zero
push "0"
jmp reverse ;<<<<<<<<<<<<<<<<<<<<
Updated in first post. :thumbsup: