FAQ: What’s a Macro?

NESmaker users probably came across these little helpful bits and pieces of code: macros. What are they and why are they used?

A macro – in terms of Assembly and NESmaker, but also in a lot of other software development environments – is a set of code instructions, built to be easily applied or inserted into the game. A macro saves on scripting time: instead of having to type out the same set of instructions every time you need it, you can just insert the macro name in your code and the assembler will replace that name with the correct set of instructions.

An analogy in everyday life that comes to mind, is abbreviations. If you’re writing an essay on, let’s say, the Nintendo Entertainment System, but you don’t feel like typing out the words Nintendo Entertainment System everytime you want to say Nintendo Entertainment System, you can abbreviate it to NES. You’ll have to define what NES means only once in your essay, and from that moment on, you can simply type NES instead of Nintendo Entertainment System, saving you quite some time in the long run.

A macro will not save bytes from your compiled game though! When a game gets compiled from code, on every spot a macro is referenced, the reference will be completely replaced with the actual macro code. Looking at the aforementioned abbreviation example, imagine the compiler opening up your essay, searching for the abbreviation NES, replacing it with Nintendo Entertainment System and exporting it to a different file. If you have to use and reuse macros a lot – up to the point where your game code is too big to be compiled to a ROM – you’ll probably want to use a subroutine instead. I’ll talk you up on that topic in another post though.