BaseAscii      PROTO :DWORD, :DWORD

Num            dd  0
szBuff         db  20 dup(?)

;==========================================================================
; Converts a 32 bit num value to an ascii string.                        *
;==========================================================================
;INVOKE     BaseAscii, Num, addr szBuff
BaseAscii PROC  uses esi edi  Input:DWORD, Output
      
         mov     eax, Input
         mov     edi, Output

      .if (eax != 0)
         .if sdword ptr eax < 0            ; Check for negative number
               mov     byte ptr [edi], '-' ; Store a minus sign
               inc     edi
               neg     eax                 ; and invert the value
         .endif
            mov     esi, edi               ; Save pointer to first digit
            mov     ecx, 10
         .while (eax > 0)                  ; Is there is more to convert
               xor     edx, edx
               div     ecx                 ; Put next digit in edx
               add     dl, '0'             ; Convert to ASCII
               mov     [edi], dl           ; Store it
               inc     edi
         .endw

            mov     byte ptr [edi], 0      ; Terminate the string

         .while (esi < edi)                ; Reverse the string
               dec     edi
               mov     al, [esi]
               mov     ah, [edi]
               mov     [edi], al
               mov     [esi], ah
               inc     esi
        .endw

      .else
            mov     word ptr [edi], 0030H  ; String "0", 0 in little endian
      .endif
         ret
BaseAscii ENDP
