I think Macro Procedure is the super set, so it can accomplish all the tasks finished by Text Macro and Macro Function. But why does MASM still provide Text Macro and Macro Function to bu used in program?
for buildtime macros, we usually wish to express a syntactical statement, but for runtime macros, we want to exitm and express a value into a register.
for buildtime macros, we usually wish to express a syntactical statement, but for runtime macros, we want to exitm and express a value into a register.
but which is buildtime macro, which is runtime macro?
A runtime macro generally ends with a statement like EXITM <EAX>
This implies that the output of the macro is to be shoved directly into EAX register, ready for use within the code that called the macro.
Buildtime macros generally don't return values in this way - instead, they express sourcecode - once such a macro has been completely 'expanded' into a series of plaintext sourcecode statements, the assembler will then interpret them - first it Expands the macro into plaintext, then it Interprets the expanded series of statements.
We use these to compose the sourcecode differently depending on the inputs presented to the macro.
This means we don't need to write several versions of some very similar block of code.
But just to confuse you - theres no reason why a buildtime macro can't emit a runtime macro !!!
Its possible to write a macro that creates a macro !
This implies that the output of the macro is to be shoved directly into EAX register, ready for use within the code that called the macro.
Buildtime macros generally don't return values in this way - instead, they express sourcecode - once such a macro has been completely 'expanded' into a series of plaintext sourcecode statements, the assembler will then interpret them - first it Expands the macro into plaintext, then it Interprets the expanded series of statements.
We use these to compose the sourcecode differently depending on the inputs presented to the macro.
This means we don't need to write several versions of some very similar block of code.
But just to confuse you - theres no reason why a buildtime macro can't emit a runtime macro !!!
Its possible to write a macro that creates a macro !
Oh, a very difficult topic!
Basically, I want to know when I should use text macro, when I should use macro procedure, and macro function.
Basically, I want to know when I should use text macro, when I should use macro procedure, and macro function.
Use string equates where the macro is working specifically on string manipulation,and at buildtime.
Otherwise use macros to express either repeats of a common block of code, or slight variations of them.
The purpose of a macro is not to hide whats really happening in a block of code, but to eliminate laborious typing of quite similar blocks of code.
Otherwise use macros to express either repeats of a common block of code, or slight variations of them.
The purpose of a macro is not to hide whats really happening in a block of code, but to eliminate laborious typing of quite similar blocks of code.