SCM is a kind of programmable device. The appearance of SCM makes the hardware design more simple and the function of the product more powerful. The program is the soul of SCM. At present, the electronic products with a little more complex functions are all based on the single chip microcomputer, and then the peripheral circuits are used to realize the functional requirements. The programming of MCU can be realized by assembly language and C language.

1. Characteristics of assembly programming

Assembly is a low level language which is closer to the bottom of hardware. The bus and address are very important in hardware programming. In assembly language, mnemonics are usually used to replace the operation code of machine instructions, and labels are used to represent the address of operands. Therefore, there is a unique corresponding relationship between assembly language and machine instructions, which leads to the assembly instruction set of single-chip microcomputer which is not connected. This is more troublesome, because after changing the MCU or upgrading the old product, the original assembly code is difficult to transplant across platforms, and can only be rewritten. Therefore, the portability of assembly is very poor, because it is a direct operation of machine instructions, so the readability is also very poor. This is the two biggest disadvantages of assembly language, but its advantage is that the execution efficiency is very high. In terms of convenience, assembly is convenient for hardware, but not friendly for engineers.

2. Characteristics of C programming language

In the past few years, there were quite a lot of people who used assembly programming. Now, the fewer people used assembly. Even people who write drivers do not use assembly completely, but use the combination of assembly and C language. The C language programming of single chip microcomputer has two greatest advantages.

The first advantage: easy to transplant

There have been MCU C language programming colleagues have such experience, in programming, first of all in the initialization of SCM registers, after the configuration of the code is no longer frequent contact with registers, so make the level of C language is very clear, in the transplant code, just according to the new platform to modify the register configuration part, the main function There is almost no need to modify the part. This is also the reason why many excellent programmers advocate hierarchical document programming. Each function block corresponds to a C file and a h header file. When porting, you only need to copy these two files away, which is convenient for porting.

From this point of view, we can put aside the register configuration of MCU to achieve programming, which is better, such as the official library programming of STM32 and CMSIS.

Second advantage: easy to read

Because C language establishes the relationship between registers and hardware drivers / interfaces, programmers no longer need to memorize boring instructions, and the hierarchical and modular programming of C language greatly improves the readability of the code. Compared with assembly, C language can achieve more complex functions with less code, and it is easier to understand. That’s why C is becoming more and more popular.

3. The advantages of C language over assembly

From the previous description, we can see that C language has more advantages, C language is easy to transplant across platforms, C language is easy to understand, and C language is easy to continue. In short, from the programming point of view, C language is more popular with programmers.

Leave a Reply

Your email address will not be published. Required fields are marked *