Hi,
Is there a printf() equivalent in MASM32? Sending formated output directly to the console, other than making a call to wsprintf/StdOut combo:
invoke wsprintfA, addr buffer, addr format, ...
invoke StdOut, addr buffer
Thanks,
-chris
Chris,
I have had a go at something similar with masm macros to "printf" string formatting in terms of escapes but they are not written to do the numeric conversion like printf is. The problem with using the MSVCRT printf directly is the C compiler does the escapes which are not part of the actual function. Greg Lyons did a whole heap of msvcrt maths conversions and in conjunction with a couple of macros in masm32 where you can concatenate string data so its possible if you want that type of string function emulation.
You will find a few limitations due to masm's own escapes but they are not hard to get around.
Thanks hutch.
The reason I asked is because I am writting a procedure that works similar to printf function. I am just checking so that I don't need to repeat something that's already been done by somebody else.
Cheers and belated happy birthday, :dance:
-chris
Hi gwapo,
Have a look at Poasm, it supports C escapes.
gwapo,
If you INCLUDE msvcrt.inc and INCLUDELIB msvcrt.lib, you can INVOKE printf like so:
INVOKE crt_printf, ADDR szFormat, arg1, arg2
Here is a macro that I wrote and use:
printf MACRO pszFmt, args:VARARG
IFB <args>
IFB <pszFmt>
INVOKE crt_printf, SADD(10)
ELSE
INVOKE crt_printf, pszFmt
ENDIF
ELSE
INVOKE crt_printf, pszFmt, args
ENDIF
ENDM
Vortex,
Thanks, I'll try to download PellesC later and play around with PoASM.
Greg,
Very much appreciated, that macro you just gave saves a lot of work.
Cheers,
-chris
I've implemented a similar function to printf in my ASM Runtime called Format (or Print, to send it directly to the console). I believe it's much simpler, neater and more useful in terms of assembly language programming.
Download and source are at my web page (http://web.aanet.com.au/zooba).
Cheers,
Zooba :U
Cool, thanks. I think I already downloaded it sometimes before, but I still yet to look what's inside the package.
I'll try to see your implementation of Print, thanks,
Regards,
-chris
Before you try it, I highly recommend viewing the documentation.
The relevant page is online here (http://web.aanet.com.au/zooba/ASMRTDoc/Format.htm), but it is from the next version (0.126) which hasn't been released yet. The only differences (when using the macro in version 0.125) are that the maximum field width is 63 and there's no 64-bit hex types.
Cheers,
Zooba :U