The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: gwapo on June 20, 2006, 08:21:07 AM

Title: printf() in MASM
Post by: gwapo on June 20, 2006, 08:21:07 AM
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
Title: Re: printf() in MASM
Post by: hutch-- on June 20, 2006, 08:41:09 AM
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.
Title: Re: printf() in MASM
Post by: gwapo on June 20, 2006, 08:53:56 AM
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
Title: Re: printf() in MASM
Post by: Vortex on June 20, 2006, 09:44:06 AM
Hi gwapo,

Have a look at Poasm, it supports C escapes.
Title: Re: printf() in MASM
Post by: GregL on June 20, 2006, 05:43:53 PM
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   

Title: Re: printf() in MASM
Post by: gwapo on June 21, 2006, 01:12:43 AM
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
Title: Re: printf() in MASM
Post by: zooba on June 21, 2006, 03:26:54 AM
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
Title: Re: printf() in MASM
Post by: gwapo on June 21, 2006, 06:53:47 AM
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
Title: Re: printf() in MASM
Post by: zooba on June 22, 2006, 10:02:49 AM
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