9.2.1 Tip #8 Data Types and Sizes
In addition to reducing code size, selecting a proper data type and size will reduce execution time as well. For AVR 8-bit, accessing 8-bit (Byte) value is always the most efficient way.
The table below shows the difference between 8-bit and 16-bit variables.
16-bit variable | 8-bit variable | |
---|---|---|
C source code |
|
|
AVR Memory Usage |
Program: 94 bytes (1.1% Full) (.text + .data + .bootloader) Data: 0 bytes (0.0% Full) (.data + .bss + .noinit) |
Program: 92 bytes (1.1% Full) (.text + .data + .bootloader) Data: 0 bytes (0.0% Full) (.data + .bss + .noinit) |
Cycle counter | 90 | 79 |
Compiler optimization level | -O2 | -O2 |
Note: The loop will be unrolled by compiler automatically with –O3 option. Then the loop
will be expanded into repeating operations indicated by the loop index, so for this
example there is no difference with –O3 option enabled.