The efficiency of C51 program compilation to generate assembly code is determined by many factors. For Keil C51, it is mainly affected by the following two factors:
Section 1 The impact of storage mode
The storage mode determines the storage space of the default variables, and the complexity of the assembly code for accessing variables in each space determines the code rate.
For example, if an integer variable i is placed in memory space 18H and 19H, the ++i operation is compiled into four statements:
INC 0x19
MOV A,0x19
JNZ 0x272D
INC 0x18
0x272D:
If it is placed in the external memory space 0000H, 0001H, the ++i operation is compiled into nine statements:
MOV DPTR, 0001
MOVX A, @DPTR
INC A
MOVX @ DPTR,A
JNz #5
MOV OPTR,#0000
MOVX A,@DPTR
INC A
MOVX @ DPTR,A
As for the statements after assembly, the code rate of operations on external memory is much lower than that of internal memory operations. The generated statements are more than twice that of memory, and there are a large number of such operations in the program, which shows the impact of storage mode on code rate.
Therefore, the principle of programming is
1. Select the storage mode from small-compact-large in sequence. If there are too many variables, choose large mode.
2. Even if the large mode is selected, it is best to store some commonly used local variables or variables that can be placed in memory in order to maximize the code rate of the program.
Section 2 The impact of program structure
The structural units of a program include modules, functions, etc. For the same function, if the structure is more complex, it involves more operations, variables, functional modules and functions, etc., and the code rate is naturally much lower than that of a program with good structure and simple code.
In addition, the program's running control statements are also a key factor affecting the code rate. For example, many compilers translate switch-case statements into very complex forms, and Keil C51 is no exception. Relatively simple Switch-case statements are compiled into jump instruction forms with a higher code rate, but for more complex Switch-Case, a system library function ?C?ICASE must be called for processing, which is very complicated.
For example, if(), while(), etc. statements also have relatively low code length, but after compilation, they are much higher than switch-case.
Therefore, it is recommended that designers use as few statements as possible such as switch-case to control the program structure in order to improve the code rate.
In addition to the above two points, other factors will also affect the code rate, such as:
Whether to pass parameters using registers, that is, whether the NOAREGS option is enabled
Whether to include debugging information: DEBUG option
Whether to include extended debugging information: BJECTEXTEND
Previous article:Classic 4*4 matrix keyboard C51 program
Next article:Add assembly method to keil c file
- Popular Resources
- Popular amplifiers
- 西门子S7-12001500 PLC SCL语言编程从入门到精通 (北岛李工)
- Siemens Motion Control Technology and Engineering Applications (Tongxue, edited by Wu Xiaojun)
- How to read electrical control circuit diagrams (Classic best-selling books on electronics and electrical engineering) (Zheng Fengyi)
- MCU C language programming and Proteus simulation technology (Xu Aijun)
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
- [Erha Image Recognition Artificial Intelligence Vision Sensor] 2. Power supply test and firmware upgrade
- NB-IOT data adding problem in transparent transmission cloud data
- 【TouchGFX Design】Use of Scroll List & Scroll Wheel in Control Container
- What is millimeter wave? -- "Millimeter wave basics" (white paper)
- Talking about five dollars: How deep is the water in children's phone watches?
- Samsung Suzhou factory announced major layoffs!
- Gaoyun FPGA reports the error "suitable range is from 400MHz to 1200MHz"
- Simple summary of Android Bluetooth pairing communication, app layer implementation of Bluetooth silent pairing, ClsUtils class
- The problem of self-reduction
- Power supply decoupling capacitors