How to reduce the length of compiled code in keil C51 language programming

Publisher:暗里著迷Latest update time:2012-08-13 Source: 51heiKeywords:keil Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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

Keywords:keil Reference address:How to reduce the length of compiled code in keil C51 language programming

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

51 MCU uses printf for serial port output in Keil
Recently, some students are troubled by the problem of how to use the serial port of the microcontroller to output and display on the host computer serial port assistant during the learning process of 51 single-chip microcomputer. In fact, many development environments support the use of the most commonly used printf
[Microcontroller]
Keil C51 detailed settings
1. Change the target name After opening Keil, the target in the Project Workspace on the left can be modified. The method is: right-click Target - Manage Compnents - double-click the item to be modified. If you want to add, use the corresponding toolbar in the dialog box. 2. Option for target setting TARGET item 1
[Microcontroller]
[C51 self-study notes] ULN2003 + buzzer + relay + stepper motor
ULN2003: ULN2003 is a high voltage, high current Darlington array, consisting of seven silicon NPN Darlington tubes. High current drive array, mostly used in control circuits such as single chip microcomputers, intelligent instruments, PLCs, digital output cards, etc. It can directly drive loads such as relays. Co
[Microcontroller]
[C51 self-study notes] ULN2003 + buzzer + relay + stepper motor
Buzzer alarm sound C51 program
Buzzer alarm sound C51 program #define uchar unsigned char //Macro definition for easy use #define uint unsigned int #define ulong unsigned long #include //Include a 52 standard kernel header file sbit BEEP=P0^7; //Buzzer output pin /******************************************************************** Function name: m
[Microcontroller]
C51 single chip microcomputer and computer serial communication circuit diagram and source code
C51 MCU and Computer Serial Communication Circuit Diagram and Source Code 51 MCU has a full-duplex serial communication port, so serial communication can be easily performed between the MCU and the computer. Certain conditions must be met when performing serial communication. For example, the computer's seria
[Microcontroller]
Porting s3c2440 ads program to keil (I) Preliminary completion
1 Add the project to compile just like any other project 2440init.s(8): error: A1023E: File "option.inc" could not be opened:  etc.  Directly put option.inc Memcfg.inc 2440addr.inc directly in the directory of 2440init.s Then compile the current error and it will disappear 出现 .led.axf: Error: L6238E: 2440ini
[Microcontroller]
Porting s3c2440 ads program to keil (I) Preliminary completion
Mini2440----Building the debugging and downloading environment under Keil for ARM
Off-topic: Recommended compilation environment selection For those who are new to ARM bare metal programming, I would like to remind you about the choice of compilation environment. Currently, there are three mainstream ones: ADS+AXD, KEIL FOR ARM, and IAR FOR ARM. I started using ADS+AXD for learning because it comes
[Microcontroller]
Using global and external variables to implement C51 inability to call A51 functions
The article "Realization of ASM51 Calling C51 Function without Parameters" by Gou Shuai was published in the 7th issue of "Application of Electronic Technology" in 2001. It expounds the realization principle of ASM51 calling C51 function without parameters and gives examples to verify the superiority and feasibility
[Microcontroller]
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号