Close

Optimisation

A project log for Switcher

A switch mode power supply controlled by an 8051 processor.

ashley-robinsonAshley Robinson 12/31/2016 at 01:300 Comments

The functionality of the project almost complete code must be optimised to reach the target of 1024 bytes or less.

In this example the two functions under inspection regard UART traffic. One to load the buffer which is unloaded from a timer and the second is used to move data between an unsigned 16-bit integer and ASCII representation of that number. Working from left to right in the image below the code size improvement is as follows...

  1. 1021 bytes
  2. 1016 bytes
  3. 1004 bytes

The first step replaces an if statement with a modulus operation to control wrap around of the UART buffer. The second step shifts an if statement to the end of a loop to reduce the number of jump operations the compiler generates.

The more bytes than can be removed from the generated assembly will enable more options to be placed in the UART menu structure. Similar techniques will be used to reduce code size where possible.

Discussions