Analysis of MCU assembly language and the most commonly used high-level languages

Publisher:清晨微风Latest update time:2015-03-27 Source: diangonKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
      There are many programming languages ​​for microcontrollers, which can be roughly divided into three categories: machine language, assembly language, and high-level language. Machine language is no longer used by general users because it is cumbersome and prone to errors. The following analyzes the assembly language of microcontrollers and the most commonly used high-level language.

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.

Keywords:MCU Reference address:Analysis of MCU assembly language and the most commonly used high-level languages

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

Application of single chip microcomputer in permanent magnet brushless DC motor drive system of electric golf cart
introduction The first decade of the 21st century has almost passed quietly, but the era of electric transportation that people longed for has not arrived as expected. When many electric vehicle projects led by the government and actively participated by enterprises and research institutions, such as PNGV, Free
[Microcontroller]
Application of single chip microcomputer in permanent magnet brushless DC motor drive system of electric golf cart
C language program for addition, subtraction, multiplication and division calculator in 51 single chip microcomputer 100
#include //Include file    #define uchar unsigned char #define uint unsigned int char b ={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6, 0xa1,0x86,0x8e,0x8c,0xc1,0xce,0x91,0x89,0xc7,0xff}; // Common cathode character code //Delay function, used to implement short delay in the program
[Microcontroller]
MCU 3.3V GPIO controls 5V on/off
In the HUB-RPA project, the F340  GPIO  output is only 3.3V. Using it to control the on and off of USB 5V with only one PMOS has problems. After the circuit is modified as follows, the on and off of USB 5V can be controlled normally.
[Microcontroller]
MCU 3.3V GPIO controls 5V on/off
51 MCU connected to 24C02-C language test code
I summarize 3 points that need attention 1. Turn off non-IIC communication devices. For example, my development board's SDA and SCL are also connected to DS1302, which will cause interference and no results. 2. In response to IIC communication, the transmitter sets SDA to 1 when SCL is 0, and waits for the receive
[Microcontroller]
The following factors affect the power consumption of PIC microcontrollers:
I have been working on the power consumption of PIC microcontrollers. Since the project is powered by batteries, the power consumption issue is very important. According to the data sheet and information on the Internet, the power consumption of microcontrollers is mainly affected by the following factors:   1: All I/
[Microcontroller]
A single-chip microcomputer implements a timer with power-off memory function
project description: Use a single-chip microcomputer to realize 0 ~ 99s timing, display the timing in real time on the LCD, and use 24C02 to realize power-off memory. The simulation schematic is as follows: The C language code is as follows: /*------------------------ FileName: clock.h Function: Header file Author
[Microcontroller]
A single-chip microcomputer implements a timer with power-off memory function
Application of SPMC65x MCU in Induction Cooker
1 Introduction The electromagnetic cooker is an advanced electronic cooker for modern families to cook food, which uses the principle of electromagnetic induction for heating. It is very convenient to use and can be used for various cooking operations such as boiling, frying, frying, steaming, and stir-frying. Featu
[Microcontroller]
The first in China! The domestically produced, independently controllable, high-performance automotive-grade MCU DF30 chip is released
On November 10, according to the introduction released by Wuhan Economic and Technological Development Zone, on November 9, the 2024 Annual Conference of Hubei Automotive-Grade Chip Industry Technology Innovation Consortium was held in Wuhan Economic and Technological Development Zone. At the meeting, the
[Automotive Electronics]
The first in China! The domestically produced, independently controllable, high-performance automotive-grade MCU DF30 chip is released
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号