9.1.7 Tip #7 Low Level Assembly Instructions
Well coded assembly instructions are always the best optimized code. One drawback of assembly code is the non-portable syntax, so it's not recommended for programmers in most cases.
However, using assembly macros reduces the pain often associated with assembly code, and it improves the readability. Use macros instead of functions for tasks that generates less than 2-3 lines assembly code. The table below shows the code usage of assembly macro compared with using a function.
Function | Assembly Macro | |
---|---|---|
C source code |
|
|
AVR Memory Usage |
Program: 90 bytes (1.1% Full) (.text + .data + .bootloader) Data: 0 bytes (0.0% Full) (.data + .bss + .noinit) |
Program: 86 bytes (1.0% Full) (.text + .data + .bootloader) Data: 0 bytes (0.0% Full) (.data + .bss + .noinit) |
Compiler optimization level | -Os (Optimize for size) | -Os (Optimize for size) |
Refer to AVR-Libc User Manual for more details.