Assembly language: macros vs procedures

Catalin Vasile picture Catalin Vasile · Dec 6, 2012 · Viewed 8.7k times · Source

I'm new to assembly language and this question came across to my mind: Which is better solution for structuring my code, macros or procedures? While code included in a macro is just copied to the sections needed, and allowing executions of code without costly jumps, it does add extra instructions that must be loaded at the execution of the program. Also, at procedures, while it reduces the code that need to be loaded in memory, it also adds up expensive jumps, going from a section of cod to another. Which one is better? Macros or procedures?

Answer

Jonathan Wood picture Jonathan Wood · Dec 6, 2012

In general, you should be using procedures. Procedures help organize your code, can make it easier to debug and avoids duplicating the same code. Macros can be used when creating a common syntax for smaller tasks makes your code easier to read.

Of course, in cases where you are really concerned about performance and not at all concerned about the size of your code, you might stretch this general approach to favor a bit more macro use.

In the end, you have to look at each specific case. But I can tell you that I've inherited code before that overused macros. Not only did it duplicate more code, but it took a long time to figure out the source code because I had to track down all those macro definitions and figure out what they were actually doing.