This info is a part of the AVR ATMEL document.
But the points given here applies for almost all the microcontroller.
1. Compile with full size optimization.
2. Use local variables whenever possible.
3. Use the smallest applicable data type. Use unsigned if applicable.
4. If a non-local variable is only referenced within one function, it should be
declared static.
5. Collect non-local data in structures whenever natural. This increases the possibility
of indirect addressing without pointer reload.
6. Use pointers with offset or declare structures to access memory mapped I/O.
7. Use for(;;) { } for eternal loops.
8. Use do { } while(expression) if applicable.
9. Use descending loop counters and pre-decrement if applicable.
10. Access I/O memory directly (i.e., do not use pointers).
11. Declare main as C_task if not called from anywhere in the program.
12. Use macros instead of functions for tasks that generates less than 2-3 lines
assembly code.
13. Reduce the size of the Interrupt Vector segment (INTVEC) to what is actually
needed by the application. Alternatively, concatenate all the CODE segments
into one declaration and it will be done automatically.
14. Code reuse is intra-modular. Collect several functions in one module (i.e., in one
file) to increase code reuse factor.
15. In some cases, full speed optimization results in lower code size than full size
optimization. Compile on a module by module basis to investigate what gives the
best result.
16. Optimize C_startup to not initialize unused segments (i.e., IDATA0 or IDATA1 if all
variables are tiny or small).
17. If possible, avoid calling functions from inside the interrupt routine.
18. Use the smallest possible memory model.
No comments:
Post a Comment