Difference: 1. Assembly language has high efficiency, while C language has relatively low efficiency; 2. Assembly language has strong controllability of hardware, while C language has poor controllability of hardware; 3. Assembly language target code is small in size , C language object code is large in size; 4. Assembly language is not easy to maintain, but C language is easy to maintain; 5. Assembly language has poor portability, but C language has good portability, etc.
The operating environment of this tutorial: windows7 system, c99 version, Dell G3 computer.
The difference between assembly language and c language
1. Different efficiency
Assembly efficiency is high , C language efficiency is relatively low.
2. Different controllability of hardware
Assembly has strong controllability of hardware, while C language has poor controllability of hardware.
3. Different code sizes
The assembly target code is small, while the C language target code is large.
4. Different maintainability
Assembly is not easy to maintain, but C language is easy to maintain.
5. Different portability
The portability of assembly is very poor, but the portability of C language is very good.
6. Different learning difficulties
Assembly language requires a lot of complex programming knowledge and is often used by developers. C language is a very simple and convenient language, and programmers do not need to have much professional knowledge.
Expand knowledge:
The reason why assembly language has high operating efficiency:
1. Assembly Language is essentially a mnemonic for machine language.
CPU can only run the instruction set it supports, and each instruction in these instruction sets is a sequence of binary numbers, that is, an ordered combination of "0" and "1"; "0" The combination of " and "1" is not convenient for programmers to remember, so there are mnemonics such as "MOV A 0x40".
So compiling assembly language into machine language executable by the CPU only requires a translation action. After writing a program in C language, a compiler needs to be used to compile the C language into machine language corresponding to the corresponding CPU instruction set.
Assembly language and machine language have a one-to-one correspondence. But what about C language? Of course it's not such a good thing.
The syntax of C language is fixed. When a program written in C language is compiled into machine language instructions that the CPU can understand, there is no one-to-one correspondence. Therefore, compilation rules are required, so the operating efficiency is lower. It can also be said that C language is a language for programmers, while assembly language is a language directly for the CPU.
2. Assembly is a language that directly faces the CPU. As long as it is within the scope supported by the instruction set, assembly language can directly and flexibly manage every byte including special function registers, general registers, and storage units. , even every bit.
The C language is also very powerful in its use and management of memory, but after all, it is still subject to syntax. To give the simplest example, there is no variable type corresponding to three bytes or five bytes in C language, either int type or long type, so each application must be a fixed number of bytes, which will inevitably cause memory usage. waste.
Most assembly languages do not have such syntax at all. With the help of pseudo-instructions (which actually only improve readability), assembly language programs can use variables of any number of bytes. Of course, the processing is faster than C language is much more troublesome. In the end, it is still processed byte by byte, but writing a program in C language is easier. Don't worry about it, the compiler will eventually take care of it.
The price of ease is waste. Inefficient memory usage will also affect the overall efficiency of the entire program.
For more related knowledge, please pay attention to PHP Chinese website! !
The above is the detailed content of What are the differences between assembly language and c language?. For more information, please follow other related articles on the PHP Chinese website!