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

TTI Transportation Resource Center

April 8, 2024
From sensors to vehicle electrification, from design to production, on-board and off-board a TTI Transportation Specialist will help you keep moving into the future. TTI has been...

Cornell Dubilier: Push EV Charging to Higher Productivity and Lower Recharge Times

April 8, 2024
Optimized for high efficiency power inverter/converter level 3 EV charging systems, CDE capacitors offer high capacitance values, low inductance (< 5 nH), high ripple current ...

TTI Hybrid & Electric Vehicles Line Card

April 8, 2024
Components for Infrastructure, Connectivity and On-board Systems TTI stocks the premier electrical components that hybrid and electric vehicle manufacturers and suppliers need...

Bourns: Automotive-Grade Components for the Rough Road Ahead

April 8, 2024
The electronics needed for transportation today is getting increasingly more demanding and sophisticated, requiring not only high quality components but those that interface well...

Comments

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