What are the merits and demerits of using C over assembly language for mcu programming.
thank you
ece
You produce code faster using C.
You will get a lot fewer hard-to-find errors with C. The compiler notices uninitialized variables etc.
The code is easier to move to a different processor, since C is universally available. Only specific language extensions to take advantage of the architecture or code that manipulates bits in the processor will be non-portable or require some rewrites if changing to a different processor.
It is easier to rewrite the code to extend (or change) it's behaviour since the compiler and the language encapsulation will often catch partial rewrites.
It is easier for another developer to look at the code and understand it, or to be able to take over.
It is easier to debug. A higher-level language means that more can happen for each line when single-stepping. A single multiply or division in C can require a lot of assembler instructions if the processor doesn't have hardware instructions for multiply or divide.
The code may be a bit bigger/slower - but only if you have reasonably good knowledge of assembly for the specific processor. A lousy assembler programmer will loose to a compiler.
"Only (sic) specific language extensions to take advantage of the architecture or code that manipulates bits in the processor will be non-portable or require some rewrites if changing to a different processor."
Those parts will certainly need re-writing - but they are not the only parts!
There are many details of the 'C' language which are implementation-defined - any code which relies on such details will be non-portable.
But there are techniques to "encapsulate" these dependencies so that porting can be quite painless.
With assembler, you can't even guarantee that a different assembler for the same architecture will have even remotely similar syntax!
View all questions in Keil forum