Programming C Without Knowing Assembly

In the comments, Christopher Thomas asks:

Can an Embedded Systems developer program well in C without knowing the assembly language of the processor he or she is developing with?

Absolutely. In my professional life, I avoid using assembly wherever possible. If I need to drop down to assembly to start a new processor, do some weird fast interrupt processing, or use a machine instruction that isn’t available to C, I budget myself 200 lines of assembly, and make sure that I never get close.

Programming assembly is done with a keyboard in one hand, the language manual in another, and a debugger in a third. That is no way to be productive, but if it needs to be done you do it. The syntax of assembly is intentionally abusive to humans, using commands like:

bra strap

rather than:

branch BootLoader

and

eieio

to enforce in-order execution. Apparently saving a few characters on the mnemonics is efficient, or some sort of twisted badge of honor. Is this stuff that you should know? No, let the compiler generate it.

Certainly, you can become fluent in assembly to the point where you are not using the manual,  but recently I have programmed MC68XXX, 68HC12, PowerPC, Coldfire, PIC, ARM, and X86 processors in C, and becoming fluent in the assembly language of all of them would be a career in itself. Two assemblers for the same processor will have their own dialects, and the syntax can change if the assembler writers decide that it is necessary. Becoming fluent means sticking with one assembler on a particular processor, good luck with that.  (Plus, there are very few job openings that call for assembly language skills.)

Having a general knowledge of basic computer architecture, assembly language programming, and registers can help in debugging C programs, but it isn't necessary. Read through the assembly language manual to see what instructions are available, but don't go writing assembly language programs unless you need to. You might change the way you write your C code if you know the processor doesn't do floating point math, if it doesn't have a divide instruction, or if there is a table interpolate instruction that would make your code really clean.

Finally, most new processors, RISC and CISC, have an instruction set that is designed to be generated by a compiler. It isn’t targeted to be written by humans. Your C code needs to be read by humans and the compiler, modern assembly only gets read by humans when things go badly.

So, a developer should have an understanding of how a processor works and the basics of assembly language programming, but don’t spend extra time learning assembly and just avoid writing binary machine code.


This post is part of a series. Please see the other posts here.