News:

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

Output Macros

Started by cman, October 02, 2009, 05:04:36 PM

Previous topic - Next topic

cman

How would one write a macro mimicking the behavior of the stdio.h library function printf() ? Are macros that could implement the behavior of iostream.h's "cout" function possible? I'm curious as to what can be created with Masm's macro processor. Thanks for any tips....

nathanpc

You can create include files(*.inc). :U

Hope i'm  helping!

PBrennick

nathanpc,

You are correct, all '.h' files are for C or C++ what '.inc' files are for assembly. .h files can and constantly are converted to .inc files but sometimes it can involve a bit of effort. Merely renaming the file will not work. Japheth has a tool to do this which works most of the time. Take a look at his excellent site.

Paul
The GeneSys Project is available from:
The Repository or My crappy website

GregL

cman,

A macro mimicking printf could be done, but it would be a lot of work.  cout would be even more difficult.  Why not just use the original printf function?

Here is a printf macro I wrote (it uses MSVCRT printf).


; ====================================
printf MACRO fmt, args:VARARG
    LOCAL first
    IFB <args>
        IFB <fmt>                              ;; args is blank and fmt is blank
            INVOKE crt_printf, TEXT(CR,LF)     ;; just print a newline.
        ELSE                                   ;; args is blank and fmt is not blank
            first SUBSTR <fmt>,1,1             ;; is fmt quoted text or a pointer
            IFIDN first,<">                    ;; is the first char of fmt a double quote?
                INVOKE crt_printf, TEXT(fmt)   ;; it's quoted text
            ELSE                               ;; otherwise
                INVOKE crt_printf, fmt         ;; it's a pointer
            ENDIF
        ENDIF
    ELSE                                       ;; args is not blank and fmt is not blank
        first SUBSTR <fmt>,1,1                 ;; is fmt quoted text or a pointer
        IFIDN first,<">                        ;; is the first char of fmt a double quote?
            INVOKE crt_printf, TEXT(fmt), args ;; it's quoted text
        ELSE                                   ;; otherwise
            INVOKE crt_printf, fmt, args       ;; it's a pointer to a format string
        ENDIF
    ENDIF
ENDM
; ====================================


It requires INCLUDE msvcrt.inc and INCLUDELIB msvcrt.lib.