News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

dwtoa is checking if the value to be converted is negative number

Started by Technos, March 16, 2020, 06:16:52 PM

Previous topic - Next topic

Technos

Quote from: Vortex on March 18, 2020, 11:30:18 PM
Hi Technos,

Here is a quick example :

include     \masm32\include\masm32rt.inc

.data?

buffer      db 16 dup(?)

.code

start:

    invoke  dwtoa,-5,ADDR buffer
    invoke  StdOut,ADDR buffer

    invoke  ExitProcess,0

END start


Build the code as a console output, you should see -5 after running the executable.

Hi Vortex,

I think I may have confused a lot of people with my post - non-native English speaker here... Anyway, my understanding with dwtoa (DWORD to o ASCII?) is that it should only handle DWORD (positive numbers). For example, the following will return -1, I am expecting it to print 4294967295.

include     \masm32\include\masm32rt.inc

.data?

buffer      db 16 dup(?)

.code

start:

    invoke  dwtoa,4294967295,ADDR buffer
    invoke  StdOut,ADDR buffer

    invoke  ExitProcess,0

END start


jj2007

Hi Technos,

It's just a little glitch in the documentation, which should say SDWORD, that's all.

But thanks to your post I discovered a weird little glitch in my own Str$() implementation:
include \masm32\MasmBasic\MasmBasic.inc
  Init
  Cls
  or ecx, -1 ; 4294967295 as DWORD, 18446744073709551615 as QWORD
  PrintLine Str$("%i=", ecx), Str$("%u", ecx)
  PrintLine Str$("%i=", ecx), Str$("%u ", ecx)
EndOfCode


Output:
-1=18446744073709551615
-1=4294967295


The %u format prints a QWORD, surprise! However, if followed by a blank, it prints a DWORD. Will have to investigate :tongue:

hutch--

Timo posted the one that works on unsigned integers greater than 2 gig.

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    include \masm32\include\masm32rt.inc
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

comment * -----------------------------------------------------
                        Build this  template with
                       "CONSOLE ASSEMBLE AND LINK"
        ----------------------------------------------------- *

    .code

start:
   
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    call main
    inkey
    exit

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

main proc

    LOCAL pvar   :DWORD
    LOCAL buffer[32]:BYTE

    lea edx, buffer
    mov pvar, edx

    invoke crt__ultoa,1024*1024*1024*3,pvar,10      ; 3 gig

    print pvar,13,10

    ret

main endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

end start

raymond

Hi Technos

You may want to have a look at the smdtoa, smqtoa, umdtoa and umqtoa procedures included in the FPULIB available on this site (or on my site at ray.masm.com). The 's' and 'm' prefixes are for signed and unsigned dwords/qwords.

The "m" in the procedure name is to indicate that this procedure is based on the principal of multiplying by the reciprocal of 10 instead of dividing by 10, i.e. the use of "magic numbers".

Note: The source code of all the functions are part of the downloadable fpulib package.
Whenever you assume something, you risk being wrong half the time.
http://www.ray.masmcode.com