Macros in AVR Assembler
Macros in AVR Assembler
html
Macros in AVR assembler can be defined everywhere in the code as long as they're not used at a location before the macro
definition. They can take arguments which are replaced during assembly and can't be changed during runtime. The
arguments can only be used in the form @0 or @1 (while 0 or 1 are the argument numbers startnig from 0). The arguments
can be almost everything the assembler can handle: integers, characters, registers, I/O addresses, 16 or 32-bit integers,
binary expressions...
This works:
.macro ldi16
ldi @0, low(@2)
ldi @1, high(@2)
.endmacro
Above, I wrote that arguments are replaced during assembly. The following should make it clear:
As I said, macros can also be used to replace 16-bit calculations. This is one example (along with ldi16):
Macros can of course be more complex, take more arguments and crash the assembler. If too many macros are defined in one
file, the last ones can't be found. I've had this with more than 7 I think. Just split them into more files, that helps sometimes. Or
just don't be that lazy and write the code yourself...
1 of 1