News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

dwtoa --> qwtoa

Started by zedd151, October 20, 2024, 08:44:47 PM

Previous topic - Next topic

zedd151

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:
"We are living in interesting times"   :tongue:

sinsi

Nasty little bug if qwValue=0  :sad:
    test rax,rax
    jnz not_zero
    push "0"
    jmp reverse ;<<<<<<<<<<<<<<<<<<<<

zedd151

Updated in first post.   :thumbsup:
"We are living in interesting times"   :tongue: