The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: peaslee on November 12, 2010, 08:02:49 PM

Title: How to "include" Macros?
Post by: peaslee on November 12, 2010, 08:02:49 PM
I'm working my way through some tutorials. One describes a macro RGB for creating color values. It doesn't appear I can just tuck it into an include file, so what do I do to have it available for all the subsequent applications?

Thanks.
Title: Re: How to "include" Macros?
Post by: MichaelW on November 12, 2010, 08:16:11 PM
I think you mean the RGB macro in macros.asm. You can include macros.asm in your source (along with the .MODEL directive, etc, see the include file for the details) as part of masm32rt.inc with:

include \masm32\include\masm32rt.inc

Or separately with:

include \masm32\macros\macros.asm

Another of multiple possibilities is a macro function that returns an RGB value calculated entirely by the preprocessor (at assembly time, instead of at run time as the MASM32 RGB macro does).

    rgb MACRO red, green, blue
      EXITM % blue SHL 16 + green SHL 8 + red
    ENDM


Title: Re: How to "include" Macros?
Post by: peaslee on November 12, 2010, 08:20:51 PM
RGB was a bad choice for an example. Let's say I create an entirely new macro or perhaps a procedure that I will use frequently. I assume that it would have to be assembled and linked, but I don't know how.
Title: Re: How to "include" Macros?
Post by: dedndave on November 12, 2010, 08:25:44 PM
have a look in the masm32\macros folder
there are a few examples
another appropriate place to put them is the masm32\include folder

just make your file, stick it one of those folders, then include it in your asm file

when you INCLUDE an external file, it is as though all the text in that file is expanded at the INCLUDE directive
Title: Re: How to "include" Macros?
Post by: MichaelW on November 12, 2010, 08:28:30 PM
Create your own include file, put it in some convenient location, and include it in you source. The attachment is a quick demo.