Macro Instructions

Using Assembly language for the implementation of your ideas is fun (I surely have said that already and, probably, even more than once). However, it may become quite annoying when it comes to certain operations, which have to be re-implemented in different parts of your program. One possible solution may be implementing those operations in the form of a procedure and calling it when needed. However, this may quickly become a nuisance as well, once you have a procedure; which receives more than zero parameters. While in high-level languages you simply "pass" the parameters to a function, in Assembly, you have to actually pass them to a procedure in accordance with the calling convention of your choice, which, in turn, may imply additional headache with management of registers (if parameters are passed via certain registers) or accessing the stack. Sometimes, this complication is worth it, but that is not always the case, especially when it comes to a short set of recurring instructions. This is exactly the case where macro instructions may save us from a lot of headaches and redundant efforts, not to mention the amount of CPU time spent on calls (parameter preparations and procedure prolog and epilog), tiny fractions of a millisecond which may, at the end, aggregate into quite substantial delays.

In this chapter, we will cover the following:

  • Macro instructions and the mechanisms behind them
  • How macro instructions may be parameterized
  • Learning variadic macro instructions and power thereof
  • Getting acquainted with common calling conventions
  • Examining additional assembler directives and conditional assembly

All of this is essential for our future work with this book, as the methods and algorithms we will explore would be too cumbersome otherwise.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset