Assembly language for microcontrollers
Assembly language is a symbolic language that uses text mnemonics to represent machine instructions. It is the language that is closest to machine code. Its main advantages are that it takes up less resources and has high program execution efficiency. Since one instruction corresponds to one machine code, the execution action of each step is very clear, and the program size and stack call situation are easy to control, and debugging is also convenient. However, the assembly language of different types of microcontrollers may be a little different, so it is not easy to transplant because their instruction systems are different. But knowing assembly language can help understand the special regulations that affect the efficiency of any language. For example, knowing assembly language instructions can take advantage of variables in the on-chip RAM, because off-chip variables require several instructions to set the accumulator and data pointer for access. Similarly, when it is required to use floating-point numbers and enable functions, only those with assembly programming experience can avoid generating large and inefficient programs. For this aspect of programming, it is impossible without assembly language.
C language for microcontrollers
The C language of the microcontroller is a compiled programming language that takes into account the characteristics of multiple high-level languages and has the functions of assembly language. The C language has a rich library function, fast calculation speed, high compilation efficiency, good portability, and can directly control the system hardware. In addition, the C language program has a complete program module structure, which provides a strong guarantee for the use of modular programming methods in software development. Compared with assembly, it has the following advantages:
It is not required to understand the instruction system of the microcontroller, only a preliminary understanding of the memory structure of 51 is required. The details such as register allocation, addressing of different memories and data types are managed by the compiler.
The program has a standard structure and can be divided into different functions. This method can structure the program, combine variable selections with special operations, and improve the readability of the program.
Programming and debugging time are significantly shortened, thus improving efficiency. The library provided contains many standard subroutines, which have strong data processing capabilities and can easily implant the already compiled programs into new programs because it has convenient modular programming technology.
It is powerful and flexible, and the library provided contains many standard subroutines. It has strong data processing capabilities and can easily implant existing programs into new programs because it has convenient modular programming technology.
The C language for microcontrollers is widely supported as a very convenient language. The C language program itself does not depend on the machine hardware system and can be ported quickly according to the different microcontrollers without making any modifications.
Programming with the MCU C language has become a mainstream in MCU software development. As a MCU developer with comprehensive technology and involved in large-scale software system development, it is best to master basic C language programming.
Other high-level languages
For MCU programming, there are also basic language and PL/M language. Basic has always been considered as a language for beginners to learn programming, which is easy to get started.
The PL/M language has good readability and high reliability, but it does not support complex arithmetic operations, floating-point variables, and has no rich library function support.
Assembly language is closely related to the processor. Each processor has its own instruction system, and the corresponding assembly language is different. Therefore, the versatility and portability of assembly language programs are poor. Relatively speaking, high-level languages are independent of specific computers, and high-level language programs can be compiled and executed on a variety of computers.
Assembly language has limited functions and involves hardware details such as registers and main memory units, so it is cumbersome to write programs and difficult to debug. High-level languages provide powerful functions and use syntax similar to natural languages, so they are easy to master and apply, and they do not have to worry about trivial issues such as flags and stacks.
Assembly language is essentially machine language, which can directly and effectively control computer hardware, and thus easily produces high-efficiency target programs with fast running speed and short instruction sequences. High-level languages are not easy to directly control various computer operations, and the target programs generated by compilers are often large and difficult to optimize, so they run slowly.
To sum up, the various programming languages of microcontrollers have their own advantages and disadvantages. As a beginner of microcontrollers, you should first learn assembly language. Because assembly language programs not only have the advantages of being concise and clear, strong in jumping, and taking up less ROM resources, but also because it is closely related to the underlying hardware of the microcontroller, it can allow beginners to better understand the various resources of the microcontroller hardware system and be familiar with the functions of each functional module, thus laying a solid foundation for writing more efficient programs.
Program codes written in MCU assembly language are highly efficient, but relatively difficult to learn. Moreover, for a large project, if it is programmed entirely in assembly language, it will be very cumbersome, especially when encountering algorithmic problems, assembly language simply cannot cope with them. Moreover, the main frequency of MCU is constantly increasing. Under the effect of high-frequency clock, we do not need such high-efficiency code at all. In addition, the ROM and RAM space of MCU is also constantly increasing, which is enough to hold any program code written in C language. The information related to MCU C language is abundant and easy to find, and it is very portable. For example, the program of writing temperature sensor by changing an IO port can be used on any MCU. Programming in MCU C language has become a mainstream of MCU software development. As a technician, it is best to master basic C language programming.
Of course, sometimes the C language of the microcontroller cannot realize all the functions of the program to be written. For example, when you want to write a precisely controlled timing program, it is more convenient to use assembly language. Therefore, if you want to become an excellent microcontroller programming technician, it is best to understand the mixed programming of the C language and assembly language of the microcontroller. Because the assembly language program occupies a small storage space, has flexible hardware control, and has a fast response speed, but its readability is poor and it is difficult to debug and update and maintain. The C language is easy to update and maintain and has strong portability, but practice has proved that there are many shortcomings in using the C language alone to develop microcontroller programs, such as occupying a large storage space and inflexible hardware control. Therefore, it is not ideal to use any language alone to develop microcontroller programs. To this end, it is necessary to write a high-speed, high-efficiency, and highly portable microcontroller program, combining the respective advantages of the C language and the assembly language, and creating the so-called mixed programming of the C language and assembly language of the microcontroller. In the programming process, the C language is usually used to build the program framework, and the assembly program is used as a subroutine to handle some special applications with real-time requirements.
Previous article:The internal structure and working principle of 51 single-chip microcomputer CPU
Next article:8051 MCU and RS485 application circuit schematic diagram
Recommended ReadingLatest update time:2024-11-16 13:45
- Popular Resources
- Popular amplifiers
- Wireless Sensor Network Technology and Applications (Edited by Mou Si, Yin Hong, and Su Xing)
- Modern Electronic Technology Training Course (Edited by Yao Youfeng)
- Modern arc welding power supply and its control
- Small AC Servo Motor Control Circuit Design (by Masaru Ishijima; translated by Xue Liang and Zhu Jianjun, by Masaru Ishijima, Xue Liang, and Zhu Jianjun)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- PCB copper plating problem
- [Project source code] Using scripts in Quartus II to convert sof to rbf files
- [Flower carving DIY] Interesting and fun music visualization series of small projects (07) --- large square spectrum light
- stm32 and dht11
- Looking for a solution that can achieve high-speed USB communication with Android phones
- [NXP Rapid IoT Review] + A dazzling first experience
- What kind of long distance wireless transmission equipment is there?
- 【Tuya BK7231N】In-depth analysis of sample code
- The sipeed team will provide developers with free MAXI development boards
- CircuitPython-enabled electronic cat (MeowMeow)