In assembly programming a macro is basically a set of instruction represented by a single statement. A macro can be seen as a new instruction created by the programmer for the microcontroller.
Note however that this new instruction (the macro) is created by using the existing instructions that are provided with the AVR microcontroller.
;Initialize the AVR microcontroller stack pointer LDI R16, low(RAMEND) OUT SPL, R16 LDI R16, high(RAMEND) OUT SPH, R16
Now instead of writing the four (4) instruction to initialize the AVR stack pointer you can define a macro, say LSP, with these instructions and use this macro to replace the set of instruction as shown in the AVR assembly code below.
;Initialize the stack LSP R16, RAMEND
.MACRO LSP LDI @0, low(@1) OUT SPL, @0 LDI @0, high(@1) OUT SPH, @0 .ENDMACRO
Once you have defined your macro it can be used just like any other of the AVR microcontroller instructions. Below shows how you would use the macro just define above. Note here that @0 and @1 will be replaced by R16 and RAMEND respectively in the macro definition.
LSP R16, RAMEND
AVR Tutorials hopes this assembly tutorial on writting AVR assembly macros was beneficial to you and looks forward to your continued visits for all your microcontroller tutorial needs.