Search code examples
optimizationassemblyembeddedintel8051

What techniques are available for memory optimizing in 8051 assembly language?


I need to optimize code to get room for some new code. I do not have the space for all the changes. I can not use code bank switching (80c31 with 64k).


Solution

  • You haven't really given a lot to go on here, but there are two main levels of optimizations you can consider:

    Micro-Optimizations: eg. XOR A instead of MOV A,0 Adam has covered some of these nicely earlier.

    Macro-Optimizations: Look at the structure of your program, the data structures and algorithms used, the tasks performed, and think VERY hard about how these could be rearranged or even removed. Are there whole chunks of code that actually aren't used? Is your code full of debug output statements that the user never sees? Are there functions specific to a single customer that you could leave out of a general release?

    To get a good handle on that, you'll need to work out WHERE your memory is being used up. The Linker map is a good place to start with this. Macro-optimizations are where the BIG wins can be made.

    As an aside, you could - seriously- try rewriting parts of your code with a good optimizing C compiler. You may be amazed at how tight the code can be. A true assembler hotshot may be able to improve on it, but it can easily be better than most coders. I used the IAR one about 20 years ago, and it blew my socks off.