1. The C51 program for multiplication and division of integers is relatively large, about 9 bytes, so try not to do multiplication and division.
For example: uchar a=6; a=a*6; the second line of code requires 9 bytes, while the usual statement only has 2B.
2. Statements that define variables but do not assign values or participate in calculations are not considered code. Use short variables if possible to save RAM and code space.
For example: uchar a; This sentence has no code length. But if you assign a non-zero value uchar a=5; to character type, the code length will be 3B.
uint a=5; the integer variable assignment requires 6B bytes, which is relatively large, so define a short variable if possible.
unsigned long int a=6.0; or long int a=6.0; will add 9 bytes of code. The same is true for assigning integers and floating-point numbers.
3. For long integer variables, the compiled code is longer when signed variables participate in self-addition operations than unsigned variables, so try to use unsigned floating-point numbers.
For example: long a=2; a++; or unsinged long int a=2; a++; The code should be 15 bytes shorter. a--shortened by 12 bytes
If we replace self-increment with addition assignment, the code length is the same. a+=2; there is no difference between the two definitions.
4. Do not perform multiplication and division operations on floating point numbers. The code length will be too large. The code will be several hundred bytes longer. It is not worth it. It is better to use other methods instead.
5. For similar operations, they should be written together. For example, if you call a subroutine in the middle and then come back to calculate data, the code will be much longer. (How can the number of in and out operations not be large?)
6. When defining a variable, assign a value, and then assign the value again in the next line, which will shorten the code. For example: uint a=2; a=2; Having an extra line actually shortens the code.
For example: uint a=3, b=3; a=b; Although it is redundant, the consumption of the previous code is offset. It is equivalent to not adding any code
Previous article:PIC microcontroller: temperature sensor ds18B20 C language code
Next article:Introduction to Keil uVision4 basic data types for 51 MCU
Recommended ReadingLatest update time:2024-11-16 15:31
- 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
- Changed the layout again
- Explanation of common parameters of transformers
- GD32E231 Learning 2: GPIO drive OLED and TC0 timing interrupt
- Ofweek Talent Network recruitment and job search results, let's talk about it
- A flaw in the MSP430F672x, 673x microcontrollers
- Looking forward to Huawei's operating system!
- Test parameters of 1630MHz125 amplifier
- Analysis of the types of pads and design standards in PCB design
- Why should the power supply be set to +3.3V?
- Analysis of the composition and working principle of the radio frequency identification system