Understand The 8051's Capabilities and C51 Assembly Output.

One of THE worst things you can do in C51 code is to haphazardly use integers where unsigned chars (bytes) will suffice. Particularly when indexing arrays.

While this may seem obvious to some, in my years of changing diapers (i.e. working on code written by other's who are now off destroying some other company's software department) I have run across this mistake countless times, where the non-obvious result is at least over-bloated code and/or, at worst randomly dysfunctional code.

Does ANYONE in this industry bother taking the time to inspect the assembly code resulting from a compile? Does anyone even care? ...or is 95% of the industry filled with hacks who verify their code by functional "appearance" alone? My experience suggest the latter.

The Moral:
Keil C51 is without question top notch, but its not magic. Thus, do your career and your company a favor an make an effort to understand the 8051 indepth and understand what is and what isn't good C51 programming techniques.

[end rant]

Parents
  • I found it well worth while when I started my project to examine the assembler listing, as well as re-write the same routine in different ways to observe the changes. Once I got a good feel for what the code generator was going to do in various circumstances, and what the limitations are, I could write C without having to worry about the output in most cases.

    I continue to go back and check routines when the change in size or speed seems contrary to my expectation, as well as checking important routines or common access patterns.

    I'd recommend anyone starting on an 8051 project do the same thing to educate themselves on how to make the architecture work for you. The 8051 is quirky, and the compiler adds some quirks of its own. Those quirks can make your life miserable if you don't keep them in mind.

Reply
  • I found it well worth while when I started my project to examine the assembler listing, as well as re-write the same routine in different ways to observe the changes. Once I got a good feel for what the code generator was going to do in various circumstances, and what the limitations are, I could write C without having to worry about the output in most cases.

    I continue to go back and check routines when the change in size or speed seems contrary to my expectation, as well as checking important routines or common access patterns.

    I'd recommend anyone starting on an 8051 project do the same thing to educate themselves on how to make the architecture work for you. The 8051 is quirky, and the compiler adds some quirks of its own. Those quirks can make your life miserable if you don't keep them in mind.

Children
More questions in this forum