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.

Sponsored Recommendations

Near- and Far-Field Measurements

April 16, 2024
In this comprehensive application note, we delve into the methods of measuring the transmission (or reception) pattern, a key determinant of antenna gain, using a vector network...

DigiKey Factory Tomorrow Season 3: Sustainable Manufacturing

April 16, 2024
Industry 4.0 is helping manufacturers develop and integrate technologies such as AI, edge computing and connectivity for the factories of tomorrow. Learn more at DigiKey today...

Connectivity – The Backbone of Sustainable Automation

April 16, 2024
Advanced interfaces for signals, data, and electrical power are essential. They help save resources and costs when networking production equipment.

Empowered by Cutting-Edge Automation Technology: The Sustainable Journey

April 16, 2024
Advanced automation is key to efficient production and is a powerful tool for optimizing infrastructure and processes in terms of sustainability.

Comments

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