What are the merits and demerits of using C over assembly language for mcu programming.
thank you
ece
Doesn't matter if the embedded system is small or large.
A ring-buffer for serial data can have most of the lines reused by another project. So can most of the code from a real-time clock.
If you use software engineering when writing your applications, then you can get huge amounts of help from the compiler when switching algorithms or data structures. Assembler often don't have good enough methods to encapsulate data in structures, or to type-control variables, which means that the assembler has too little information to catch a lot of errors that are obvious to a c compiler.
It's completely irrelevant how you can abuse a language. The question is if there are a difference in readability if you write reasonably sane code.
When you have an algorithm that doesn't do what you expect, you often set a breakpoint where you want to start debugging, and then single step while trying to figure out where everything goes wrong. Writing in assembler means that you may have a huge number of small steps to single-step. It is hard to skip over all the code for a multiprecision multiply or divide, since they may be the reason for the bug. When using C, it is reasonable to think that a already tested function should do ok as long as you don't have a stack overflow. With assembler, you have to assume that you may send the wrong registers to it, or fetch the answer from the wrong registers. Or missing to pick up on any register flags after the call. Or having the function modify a flag you thought should not be affected. Hence, even if modularizing the assembly, you still have a lot more information to step through.
Yes, there are assemblers with splendid macro functionality - but those macro features are very, very specific to that assembler. Ever used an assembler that the company suddenly dropped the support for? Being forced to switch to a different C compiler may be a pita, but a very much smaller pita than being forced to switch to a different assembler.