Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assembly language: macros vs procedures

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?

like image 307
Catalin Vasile Avatar asked Dec 06 '12 17:12

Catalin Vasile


1 Answers

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.

like image 60
Jonathan Wood Avatar answered Oct 12 '22 11:10

Jonathan Wood