Why C instead ASM

ASM is a specific language, also referred as a low level programming language. It is a mnemonic to a machine code. It usually takes a long time to develop embedded programs in ASM language. Today even modern 8 bit microcontrollers are powerful and complex as they were a long time ago. The program memory of tiny chips reaches megabytes; they pack many peripherals and interfaces. Hardware code is becoming more complex; functionality grows up. This is one of the main reasons for using higher-level programming languages like C.

By using C language you do not have to go into details how the processor works at the hardware level. You don’t have to think about hardware logic and how bytes are shifted between registers. It is better to leave to the compiler.

Another advantage of C language against ASM is portability. If you work with embedded system architecture and decide to move to other, and your previous program were written in ASM, then you are stuck to rewriting this code from scratch. Using C-written programs, you can re-compile code for different microcontrollers without significant code modifications. This way, your new project code upgrade becomes an easy task.

C or other high level programming language makes it easy to save specific hardware routines into libraries which are convenient to reuse in other projects, and constantly update them for better compatibility and performance. C libraries ensure that your application can be recompiled for different MCUs by selecting different settings and other parameters.

The most crucial benefit of using high level programming language like C is that you can focus on algorithm design and spend less time on coding. You can write, understand and maintain embedded code faster and easier as one C language line can stand for multiple ASM code lines.

On the other hand, ASM language can also be used in critical parts of code where you want total control on timing and memory access, but again C compilers are improving, and sometimes programs written in C may be more efficient than written in ASM. It always depends more on developer than a programming language. The days when ASM was preferred for performance and code size are long gone. Now it is all about productivity and portability of code. If you are still deciding where to start, you better stick to C and move on to the high level of coding.

One Comment:

  1. This is a post updated and imported from winavr.scienceprog.com

Leave a Reply