News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

dwtoa

Started by DoomyD, August 22, 2008, 09:57:39 PM

Previous topic - Next topic

DoomyD

While looking through the arithmetics behind the procedure, I noticed that it could be shortened by changing the multiplier constant, please correct me if I'm wrong >,<:
_dwtoa proc dwValue, lpBuffer
   push ebx
   push edi
   push esi
      mov eax,[dwValue]
      mov edi,[lpBuffer]
      
      test eax,eax
      jnz nonzero
         mov byte ptr [edi],30h
         jmp _dwx
      nonzero:
      jns signed
         mov byte ptr [edi],2Dh
         neg eax
         inc edi
      signed:
      
      mov esi, 1999999Ah
      xor ecx, ecx
      .repeat
         mov ebx, eax
         mul esi
         mov eax, edx
         lea edx, [edx+edx*4]
         add edx, edx
         sub ebx, edx
         or bl, 30h
         mov [edi+ecx], bl
         inc ecx
      .until (!eax)
      mov [edi+ecx],al
      @@:
         mov ah,[edi]
         mov al,[edi+ecx-1]
         mov [edi+ecx-1],ah
         stosb
         sub ecx,2
      jnbe @B
      _dwx:
   pop esi
   pop edi
   pop ebx
   ret
_dwtoa endp

NightWare

hmm... not tested this one, but if i remember well, it generate few wrong values if you don't use thesvin's technic here... anyway this one is quite slow, especially for big values...

read this topic for a faster one : http://www.masm32.com/board/index.php?topic=8974.0

DoomyD

Thanks, i'll check it out =)