News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Macros

Started by felipe, June 11, 2017, 01:43:34 PM

Previous topic - Next topic

felipe

I was thinking about macros: You all know that they save the effort to write code repetedly used. But when you don't use macros for this situations, you normally (at least someone  :bgrin:) separetes this repeated code in a procedure. So you don't have to write this code so many times, you just call it. Using macros instead of a procedure will allow you to safe the effort of writing the code too many times too,like the procedure method, but would also be more efficient, because you will  save your code of so many jumps or calls (branching). So macros, at least in cases like this (probably a simple case) are not just more efficient for the programmer, but also more efficient for your app. What do you think? am I right about this or...?  8)

hutch--

They certainly do have their place as long as you understand them and what they do. Written properly they save time and allow for clear code that is just as efficient as complex hand coded code but reduce the clutter level so that code is far easier to read and maintain. It is useful to be able to write both as this is how you design macros but once you have written them you don't have to keep re-inventing the wheel. You extend this capacity by combining both library procedures and macros.

jj2007

One important feature of macros is that you can pass arguments to them, and the macro decides based on the type etc which procedure to use. Here is an example: the deb macro. You can feed it with global or local variables, with full or partial registers, and xmm3 or ST(5) will also be displayed properly. Same e.g. for Print Str$("This is ST(2): %f\n", ST(2)). Doing the same with an invoke someproc, args is possible but becomes extremely clumsy.

felipe

Thanks for your replies. Nice to hear the masters and keep learning.  :greensml: