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 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

I copied the doc string of dwtoa below which seems to indicate that it should handle DWORD and convert to string. What I have observed is that 4294967295 is converted to "-1". Reading the source code tells me that it is checking if the number is negative which should not apply for DWORD.

Am I correct to assume that dwtoa should only handle DWORD? If yes, how can I send a proposed fix for dwtoa?

dwtoa proc dwValue:DWORD, lpBuffer:DWORD

    ; -------------------------------------------------------------
    ; convert DWORD to ascii string
    ; dwValue is value to be converted
    ; lpBuffer is the address of the receiving buffer
    ; EXAMPLE:
    ; invoke dwtoa,edx,ADDR buffer
    ;
    ; Uses: eax, ecx, edx.
    ; -------------------------------------------------------------

hutch--

A DWORD is unsigned, nothing to fix. I gather you want a signed conversion.

Technos

My apologies if my post is confusing....

dwtoa is assuming that dwValue  is signed - which to me is wrong. I copied portion of dwtoa.asm below (lines 37 to 48). My un-trained eyes tell me that it is checking for negative numbers  :undecided:

    test eax,eax
    jnz sign

  zero:
    mov word ptr [edi],30h
    jmp dtaexit

  sign:
    jns pos
    mov byte ptr [edi],'-'
    neg eax
    add edi, 1

Technos

Do we have a repository somewhere where I can send a pull request?

jj2007

No. Simply zip your code and attach it here (if you need more than the 512kB permitted, you are doing something wrong) :cool:

hutch--

I did not write the procedure and it is 15 years old, what I have tended to use are 2 macros that call the respective MSVCRT functions.

unsigned  invoke crt__itoa,number,ADDR buffer,10
signed    invoke crt__ltoa,number,ADDR buffer,10

Technos

Just curious, who is maintaining masm32 (masm32v11r.zip) installer? Is there plans to grow or make it more current?

hutch--

There is not much to do in it as 32 bit OS versions will not have much added to them, I currently spend the time I have on 64 bit MASM as it has a much longer future.

Technos

The projects (MFC/C++) that i am involved with are all 32-bit applications running on 64-bit OS. It will never be converted to 64-bit. I think what I am trying to say is that 32-bit applications will be here for a long time.

Should there be volunteers does anyone wiling to mentor someone to maintain masm32 version?

hutch--

No doubt they will be with us for years but there appears to be little that is new at the OS level. It is reasonably straight forward to write 32 bit MASM modules so custom libraries are a good way to enhance C/C++ apps. If you know how to write them, doing a custom version of FASTCALL is no big deal in 32 bit MASM, you use the first 3 arguments in eax, ecx & edx then put any others on the stack and it works fine and is reliable.

If called from C/C++ you will have to stay within either C or STDCALL but its no big deal to do.

I don't see any problems for anyone who wants to write custom libraries and post them for other people to use, many have done this over time and many people have used them.

HSE

Quote from: Technos on March 18, 2020, 02:36:23 PM
Just curious, who is maintaining masm32 (masm32v11r.zip) installer? Is there plans to grow or make it more current?
Most of growth was (and still is) trough complementary packages and libraries like MasmBasic, ObjAsm32, SmplMath, ModernUI, assemblers like JWasm, AsmC and UASM, and others tools, examples, etc. Now the big package is the forum, and you can take what you need.

Equations in Assembly: SmplMath

Vortex

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.

TimoVJL

msvcrt.dll _ultoa is for unsigned long conversion

char * _ultoa( unsigned long value, char *buffer, int radix );
May the source be with you

daydreamer

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.
any return of length of ascii?eax?

my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

Vortex

include     \masm32\include\masm32rt.inc

.data

s1          db 'Buffer = %s',13,10
            db 'eax = 0x%X',0

.data?

buffer      db 16 dup(?)

.code

start:

    invoke  dwtoa,-5,ADDR buffer
    invoke  crt_printf,ADDR s1,ADDR buffer,eax

    invoke  ExitProcess,0

END start


Buffer = -5
eax = 0x3535