Author Topic: Macros  (Read 225 times)

felipe

  • Member
  • ***
  • Posts: 279
  • I love assembly language programming.
Macros
« on: June 11, 2017, 01:43:34 PM »
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)
Felipe.

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 4806
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Macros
« Reply #1 on: June 11, 2017, 02:40:04 PM »
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.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

jj2007

  • Member
  • *****
  • Posts: 7541
  • Assembler is fun ;-)
    • MasmBasic
Re: Macros
« Reply #2 on: June 11, 2017, 05:25:20 PM »
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

  • Member
  • ***
  • Posts: 279
  • I love assembly language programming.
Re: Macros
« Reply #3 on: June 12, 2017, 06:41:33 AM »
Thanks for your replies. Nice to hear the masters and keep learning.  :greensml:
Felipe.