Atmel CAVR-4 Manual De Usuario

Descargar
Página de 323
CAVR-4
Part1. Using the compiler
121
Efficient coding for 
embedded applications
For embedded systems, the size of the generated code and data is very 
important, because using smaller external memory or on-chip memory can 
significantly decrease the cost and power consumption of a system.
This chapter gives an overview about how to write code that compiles to 
efficient code for an embedded application. The issues discussed are:
Taking advantage of the compilation system
Selecting data types and placing data in memory
Writing efficient code.
As a part of this, the chapter also demonstrates some of the more common 
mistakes and how to avoid them, and gives a catalog of good coding 
techniques.
Taking advantage of the compilation system
Largely, the compiler determines what size the executable code for the application will 
be. The compiler performs many transformations on a program in order to generate the 
best possible code. Examples of such transformations are storing values in registers 
instead of memory, removing superfluous code, reordering computations in a more 
efficient order, and replacing arithmetic operations by cheaper operations.
The linker should also be considered an integral part of the compilation system, since 
there are some optimizations that are performed by the linker. For instance, all unused 
functions and variables are removed and not included in the final object file. It is also as 
input to the linker you specify the memory layout. For detailed information about how 
to design the linker command file to suit the memory layout of your target system, see 
the chaptePlacing code and data.