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.
; -------------------------------------------------------------
A DWORD is unsigned, nothing to fix. I gather you want a signed conversion.
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
Do we have a repository somewhere where I can send a pull request?
No. Simply zip your code and attach it here (if you need more than the 512kB permitted, you are doing something wrong) :cool:
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
Just curious, who is maintaining masm32 (masm32v11r.zip) installer? Is there plans to grow or make it more current?
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.
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?
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.
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.
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.
msvcrt.dll _ultoa is for unsigned long conversion
char * _ultoa( unsigned long value, char *buffer, int radix );
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?
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
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
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$() (http://www.jj2007.eu/MasmBasicQuickReference.htm#Mb1186) 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:
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
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.