News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

printf() in MASM

Started by gwapo, June 20, 2006, 08:21:07 AM

Previous topic - Next topic

gwapo

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

hutch--

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.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

gwapo

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

Vortex

Hi gwapo,

Have a look at Poasm, it supports C escapes.

GregL

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   


gwapo

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

zooba

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.

Cheers,

Zooba :U

gwapo

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

zooba

Before you try it, I highly recommend viewing the documentation.

The relevant page is online here, 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