Code efficiency of Keil C51

Publisher:幸福自由Latest update time:2016-11-18 Source: 51heiKeywords:Keil Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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


Keywords:Keil Reference address:Code efficiency of Keil C51

Previous article:Classic 4*4 matrix keyboard C51 program
Next article:Add assembly method to keil c file

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号