This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Code Size Reduction

Hi,

We have a software we ported from MSP430 to 8051 using Keil compiler. On MSP430 using IAR the code size was only 11K. However in Keil assigning data, pdata and xdata to various segments we are only able to get it down to 14K.

In this kind of segmented memory hardware (data, pdata, xdata) are there any documented best practices for coding? Also best practices for assigning data, pdata and xdata to various memory and funnctions to obtain optimal code size?

Thanks

  • On MSP430 using IAR the code size was only 11K. However in Keil assigning data, pdata and xdata to various segments we are only able to get it down to 14K.

    I'm not convinced your assumption about data segementation being the reason for this is correct. You should keep in mind that an 8051 is an 8-bit core, whereas the MSP430 is a 16-bit one. Depending on what kinds of data your code uses most abundantly, code size (and processing time) can be a whole lot larger for the same operation. If your code utilizes mostly 16-bit or larger numbers, every operation will turn into a considerably large chunk of code.

    In this kind of segmented memory hardware (data, pdata, xdata) are there any documented best practices for coding?

    Classify data objects by structural complexity. Put the complex ones (e.g. big arrays of big structs) into the more difficult memory spaces (e.g. xdata). Accessing these will be clumsy anyway, so the additional overhead of having them in xdata won't hurt that much. The more of the simple, frequently used objects go into data, the smaller and faster the code.