To Compile Or !(To Compile) Assembly Is The Question

Feb. 3, 2003
C is the language of choice for embedded development, but assembler still ranks high. This is especially true for 8-bit MCUs. But is assembler really the best choice for optimal code size and execution efficiency? For 32- and 64-bit...

C is the language of choice for embedded development, but assembler still ranks high. This is especially true for 8-bit MCUs. But is assembler really the best choice for optimal code size and execution efficiency?

For 32- and 64-bit environments, the answer is a resounding no. Assembler use is so rare that most developers don't even know how to run the assembler, let alone create a macro. Things get a little fuzzier when 16-bit processors are considered. Many 16-bit architectures lack the large register set preferred by C and C++ compiler writers. The 8-bit architectures are even harder for compilers to contend with. But even here, compilers can usually outdo the most experienced programmers.

Of course, your mileage will vary depending on the compiler used. For example, Peter Dibble, distinguished engineer at TimeSys, notes that the typical C compiler, using minimal optimization, compiles a simple signed number function down to nine instructions for the Motorola 68000 family. Clever programmers can cut it to six, but they tend to leave in the conditional jumps that match the algorithm. The best is yet to come, though.

Using a technique called superoptimization, a compiler was able to chop the size of the program down to four instructions with no jump instructions. This not only slashed the size, but also improved execution on pipeline machines. Superoptimization takes into account the entire instruction set and the side effects of each instruction. One of the first papers on the subject was by Henry Massalin, entitled "Superoptimizer—A Look at the Smallest Program," in the conference on Architectural Support for Programming Languages and Systems, 1987.

Programmers are more productive when implementing a high-level language. They also make fewer errors and the code is easier to maintain. I know that I can accomplish more with C++ or Java than with assembler, even on small projects. A good compiler is important, so check out how well your compiler optimizes.

About the Author

William G. Wong | Senior Content Director - Electronic Design and Microwaves & RF

I am Editor of Electronic Design focusing on embedded, software, and systems. As Senior Content Director, I also manage Microwaves & RF and I work with a great team of editors to provide engineers, programmers, developers and technical managers with interesting and useful articles and videos on a regular basis. Check out our free newsletters to see the latest content.

You can send press releases for new products for possible coverage on the website. I am also interested in receiving contributed articles for publishing on our website. Use our template and send to me along with a signed release form. 

Check out my blog, AltEmbedded on Electronic Design, as well as his latest articles on this site that are listed below. 

You can visit my social media via these links:

I earned a Bachelor of Electrical Engineering at the Georgia Institute of Technology and a Masters in Computer Science from Rutgers University. I still do a bit of programming using everything from C and C++ to Rust and Ada/SPARK. I do a bit of PHP programming for Drupal websites. I have posted a few Drupal modules.  

I still get a hand on software and electronic hardware. Some of this can be found on our Kit Close-Up video series. You can also see me on many of our TechXchange Talk videos. I am interested in a range of projects from robotics to artificial intelligence. 

Sponsored Recommendations

Comments

To join the conversation, and become an exclusive member of Electronic Design, create an account today!