Code optimization tricks for AVR microcontrollers
|
Using high-level language compilers such as C greatly improves the development efficiency of microcontroller-based products. But when programs are written in C and compiled by a C compiler, the code efficiency is generally lower compared to an Assembly language program. However, good knowledge of microcontroller architecture and C coding helps the developers to optimize the code for reduced size and enhanced performance. For example, if we use a “do { } while ( )” loop, an increment or a decrement loop index generates different code size. Usually we write our loops counting from zero to the maximum value (increment), but it is more efficient to count the loop from the maximum value to zero (decrement). This application note describes various code optimization tips for 8-bit AVR microcontrollers based on avr-gcc (C compiler). However, due to their general nature these tips could be implemented in other compilers or with similar compiler options, and vice versa.
|