4.5.3 How Can I Make My Code Smaller?

General advice for creating smaller code:

  • Do not mix data types.
  • Define index variables in the native word width.
  • Don't use floating-point variables when integers will suffice. When using floating-point variables, consider using the smaller math libraries.
  • Compiler option -mpa can be combined with any optimization level to reduce code size. See the following chapter in this user’s guide:

    19 Optimizations

    Note: Optimized code may be more difficult to debug.
  • When initializing an SFR, use the full name of the SFR instead of bit names. You can initialize several fields at once with this technique.
  • Instead of copying code literally into several places in your program, reorganize the shared code into functions.
  • Use the small code, small scalar, and large data memory models. Refer to the following section of this user’s guide:

    11.14 Memory Models