关于keil4编译器keil字体大小小问题

Keil C减小代码编译量大小的方法(gai)
Keil C减小代码编译量大小的方法(gai)
keil-C减小代码编译大小的方法整理
方法一:(通过优化代码减小)
1.1少做乘除运算,使用左/右移位来实现乘除
Eg ,普通:a = 0x80*4;
优化:a = 0x80&&2;
1.2在不影响运算条件下,使用短类型代替长类型
Eg ,普通: int a;
优化: char a;
1.3尽量使用无符号类型数据
Eg ,普通:char a = 56;
优化:unsigned char a = 56;
1.4回避使用浮点类型数据做乘除运算,这样代码量很大
Eg ,普通:float a = 5.3*2.5;
优化:回避使用;
1.5同一种类似操作放在一起
Eg ,普通:同一类操作多次重复书写
优化:将它们定义一个子函数,每次使用时调用
1.6使用先定义后赋值的方法比在赋值时定义更省代码量
Eg ,普通:int a = 70;
1.7使用自减优于自加,比如在做延时的时候
Eg ,普通:
void dely()
for(a = 0; a & 70; a++);
优化: void dely()
for(a = 70; a & 0; a--);
1.8全局变量定义放在main()外面,初始值放在main()里面
Eg ,普通:int a = 8;
方法二:(通过keil-C软件设置优化压缩级别)
步骤:点击 "Options for Target ***" -& 选择C51栏 -& 设置Code Optimization 下Level的级别
下面是对应级别编译器对应做的处理:
0 常数合并:编译器预先计算结果,尽可能用常数代替表达式。包括运行地址计算。 优化简单访问:编译器优化访问8051系统的内部数据和位地址。 跳转优化:编译器总是扩展跳转到最终目标,多级跳转指令被删除。
死代码删除:没用的代码段被删除。
拒绝跳转:严密的检查条件跳转,以确定是否可以倒置测试逻辑来改进或删除。
数据覆盖:适合静态覆盖的数据和位段被确定,并内部标识。BL51连接/定位器可以通过全局数据流分析,选择可被覆盖的段。
窥孔优化:清除多余的MOV指令。这包括不必要的从存储区加载和常数加载操作。当存储空间或执行时间可节省时,用简单操作代替复杂操作。
寄存器变量:如有可能,自动变量和函数参数分配到寄存器上。为这些变量保留的存储区就省略了。
优化扩展访问:IDATA、XDATA、PDATA和CODE的变量直接包含在操作中。在多数时间没必要使用中间寄存器。 局部公共子表达式删除:如果用一个表达式重复进行相同的计算,则保存第一次计算结果,后面有可能就用这结果。多余的计算就被删除。
Case/Switch优化:包含SWITCH和CASE的代码优化为跳转表或跳转队列。
全局公共子表达式删除:一个函数内相同的子表达式有可能就只计算一次。中间结果保存在寄存器中,在一个新的计算中使用。
简单循环优化:用一个常数填充存储区的循环程序被修改和优化。
循环优化:如果结果程序代码更快和有效则程序对循环进行优化。
扩展索引访问优化:适当时对寄存器变量用DPTR。对指针和数组访问进行执行速度和代码大小优化。
公共尾部合并:当一个函数有多个调用,一些设置代码可以复用,因此减少程序大小。
公共块子程序:检测循环指令序列,并转换成子程序。Cx51甚至重排代码以得到更大的循环序列。
感谢关注 Ithao123精品文库频道,是专门为互联网人打造的学习交流平台,全面满足互联网人工作与学习需求,更多互联网资讯尽在 IThao123!
Laravel是一套简洁、优雅的PHP Web开发框架(PHP Web Framework)。它可以让你从面条一样杂乱的代码中解脱出来;它可以帮你构建一个完美的网络APP,而且每行代码都可以简洁、富于表达力。
Hadoop是一个由Apache基金会所开发的分布式系统基础架构。
用户可以在不了解分布式底层细节的情况下,开发分布式程序。充分利用集群的威力进行高速运算和存储。
Hadoop实现了一个分布式文件系统(Hadoop Distributed File System),简称HDFS。HDFS有高容错性的特点,并且设计用来部署在低廉的(low-cost)硬件上;而且它提供高吞吐量(high throughput)来访问应用程序的数据,适合那些有着超大数据集(large data set)的应用程序。HDFS放宽了(relax)POSIX的要求,可以以流的形式访问(streaming access)文件系统中的数据。
Hadoop的框架最核心的设计就是:HDFS和MapReduce。HDFS为海量的数据提供了存储,则MapReduce为海量的数据提供了计算。
产品设计是互联网产品经理的核心能力,一个好的产品经理一定在产品设计方面有扎实的功底,本专题将从互联网产品设计的几个方面谈谈产品设计
随着国内互联网的发展,产品经理岗位需求大幅增加,在国内,从事产品工作的大部分岗位为产品经理,其实现实中,很多从事产品工作的岗位是不能称为产品经理,主要原因是对产品经理的职责不明确,那产品经理的职责有哪些,本专题将详细介绍产品经理的主要职责
IThao123周刊11844人阅读
编译器类(8)
最近发现在keil编译的时候,出现莫名的问题,貌似代码有被优化掉的问题,后来查了下相关的资料,貌似懂了点。
我选择的是默认的default优化方式,上网看了下,默认的是level2级别优化,最后选择level0就没有问题了
下面是网上找的资料,介绍了优化功能介绍
Getting the Best Optimized Code for your Embedded Application&
ARM Compilation Tools&
The ARM Compilation Tools are the only compilation tool s co -developed with the ARM processors, and specifically&
designed to optimally support the ARM architecture. They are a result of 20 years of development, and are recognized as the&
industry -leading C and C++ compilation tools for the ARM, Thumb, and Thumb -2 instructions sets.&
The ARM Compilation tools consist of: &
o &The ARM Compiler, which enables you to compile C and C++ code. It is an optimizing compiler, and features&
command - line options to enable you to control the level of optimization &
o &Linker and Utilities, which assign addresses and lay out sections of code to form a final image &
o &A selection of libraries, including the ISO standard C libraries, and the MicroLIB C library which is optimized for&
embedded applications&
o &Assembler, which generates machine code instructions from &ARM, Thumb or Thumb-2 assembly- level & source code &
Compiler Options for Embedded Applications &&
The ARM Compilation Tools include a number of compiler optimizations to help you best target your code for your chosen&
microcontroller device and & application area. &&
They can be accessed from within uVision by clicking on Project – & Options for Target.&
T he options described this document &can be found on the Target & an d &C/C++ & tabs &of & the &Options for Targets &dialog. &
MDK Compiler Optimizations &&
o &Cross- Module &
Optimization &takes information from a prior build and uses it to place UNUSED functions into their&
own ELF section in the corresponding object file. This option is also known as Linker Feedback, and requires you to&
build your application twice to take adv antage of it for reduced code size. &&
Cross-Module Optimization has been shown to reduce code size, by removing unused functions from your application. It&
can also improve the performance & of your application, by allowing modules to share inline code. &
o &The &M icroLIB & C library
has been optimized to reduce the size of embedded applications. It is a subset of the ISO&
standard C runtime library, and offers a tradeoff between functionality and code size. Some of the standard C library&
functions such as memcpy() & are &slower, while some features of the default library are not supported. Unsupported&
features include: &
o & Operating system functions e.g. abort(), exit(), time(), system(), getenv(), &&
o & Wide character and multi-byte support e.g. &mbtowc(), wctomb()&
o & The &stdio & file &I/O function, with the exception of stdin, stdout & and &stderr &
o & Position-independent and thread -safe code &
Use the MicroLIB C library for applications where overall performance can be traded off against the need to reduce code&
size and memory cost. &
o &Link- Time Code Generation &instructs the compiler to create objects in an intermediate format so that the linker can&
perform further code optimizations. &This gives the code generator visibility into cross - file dependencies of all objects&
simultaneously, allowing it t o apply a higher level of & optimizations. Link -time code generation &can reduce &code size, and&
allow your application to run &faster. &&
o &Optimization Levels &can also be adjusted. The different levels of optimization allow you to trade off between &the level&
of debug information &available in the compiled code, &and &the performance of the code. The following &optimization levels&
are available:&
o & - O0 &applies minimum optimizations. &
Most optimizations are switched off, and the code generated has the best debug view. &
o & - O1 & applies restricted optimization. &
For example, unused inline functions and unused static functions are removed. At this level of optimization, the&
compiler also applies automatic optimizations such as removing redundant code and re -ordering instructions s o&
as to avoid an interlock situation. The code generated is reasonably optimized, with a good debug view. &&
o & - O2 &applies high optimization (This is the default setting). & &
Optimizations applied at this level take advantage of ARM’s in-depth knowledge of the processor architecture,&
to exploit processor -specific behavio r of the given target. It generates well optimized code, but with limited&
debug view. &
o & - O3 &applies th e most aggressive optimization. &
The optimization is in accordance with the user’s & – Ospace/- Otime &choice . By default, multi - file compilation is&
enabled, which leads to a longer compile time, but gives the highest levels of optimization.
o &The &Optimize for Time checkbox & causes the compiler to optimize &with a greater focus on achieving the best&
performance & when checked &( - O time) or the smallest code siz e when unchecked ( -O space). &
Unchecking Optimize for Time & selects the &– Ospace option which &instructs the compiler to perform optimizations to&
reduce the image size at the expense of a poss ible increase i n execution time. F or example, using out -of -line function&
calls instead of inline code for large structure copies. This is the default option. & When running the compiler from the&
command line, this option is invoked using ‘ -Ospace’&
Checking Optimize for Time & selects the &– Otime option which instructs the compiler to optimize the code for the fastest&
execution time, at the risk of an increase in the image size. It is recommended that you compile the time -critical parts of&
your code with – Otime, and the rest &us ing the – Ospace & directive . &
o &Split Load and Store Multiples instructs the compiler to split LDM and STM instructions involving a large number of&
registers into a series of loads/stores of fewer multiple registers. This means that an LDM of 16 registers can &be split into&
4 separate LDMs of 4 registers each. This option helps to reduce the interrupt latency on ARM systems which do not&
have a cache or write buffer, and systems which use zero - wait state 32-bit memory. &
For example, the ARM7 and ARM9 &processor s t ake can only take & an exception on an instruction boundary. If an&
exception occurs at the start of an LDM of 16 registers in a cacheless ARM7 /ARM9 &system, the system will finish&
making 16 accesses to memory before taking the exception. Depending on the memory arbitration system, this can result&
in a very high interrupt latency. Breaking the LDM into 4 individual LDMs for 4 registers means that the processor will&
take the exception after loading a maximum of 4 registers, thereby greatly reducing the interrupt & latency.&
Selecting this option improves the overall performance of the system. &
o &The &One ELF Section per Function &option tells the compiler to put all functions into their own individual ELF&
sections. This allows the linker to remove unused functions. & &
An &ELF code section typically contains the code for a number of functions. &The linker is normally only able to remove&
unused ELF sections, not unused functions. An ELF section can only be removed if all its contents are unused.&
Therefore, splitting each function into its own ELF section allows the compiler to easily identify which ones are unused,&
and remove them. &&
Selecting this option increases the time required to compile your code, but results in improved performance . &
The combination of options applied &will depend on your optimization goal – whether you are optimizing for smallest code&
size, or best performance.&
The next section illustrates the best optimization options for each of these goals.&
Optimizing for Smallest Code Size&
To optimize your code for the smallest size, the best options to apply are:&
o &The MicroLIB C library &
o &Cross- module optimization&
o &Optimization level 2 ( -O2)&
Compile the Measure example without any optimizations &
The Measure example uses analog and digital inputs to simulate a data l ogger. &
File &-- & Open Project&
C: \Keil \ARM\Boards \Keil \MCBSTM32\Measure\Measure.uv2&
Click the &Options for Target button &
& & & & & & & & & & & & & & & & & & & & & &&
In the Target tab: &
o &Uncheck &Cross- Module Optimization&
o &Uncheck &Use MicroLIB&
o &Uncheck &Use &Link- Time Code Generation &
In the C/C++ tab:&
o &Set Optimization Level to Zero&
Then click OK &to save your changes. &
& & Project &– &Build target&
Without any compiler optimizations applied, the initial code size is 13,656 Bytes.&
MDK Compiler Optimizations &
Optimize the Measur e example for Size &
Apply the compiler optimizations in turn, and re-compile each time to see their effect in reducing the code size for the&
example. &&
o &Options for Target – &Target tab: &Use the MicroLIB C library&
o &Options for Target – &Target tab: &Use cross - mod ule optimization &- &Remember to compile twice&
o &Options for Target – & C/C++ tab: &Enable Optimization level 2 ( -O2)&
Optimization Applied &Compile Size &Size Reduction &Improvement &
MicroLIB C library &8,960 Bytes & 4,696 Bytes & 34% smaller&
Cross- Module Compilation &13,500 Bytes &156 Bytes &1.1% smaller&
Optimization level – O2 &12,936 Bytes &720 Bytes &5.3% smaller&
All 3 optimization options &8,116 Bytes & 5,540 Bytes & 40.6% smaller &
Applying all the optimizations will reduce the code size down to 8,116 Bytes.&
The fully optimized code is 5,540 Bytes smaller, a total code size reduction of 40.6%&
MDK Compiler Optimizations &
Optimizing for Best Performance&
To optimize your code for performance, the best options to apply are: &
o &Cross- module optimization&
o &Optimization level 3 ( -O3)&
o &Optimize for time&
Run the &Dhrystone benchmark without any optimizations&
The Dhrystone benchmark is used to measure and compare the performance of different computers, or the efficiency of the&
code generated for the same computer by different compilers. &
& & File &– & Open Project&
& & & C: \Keil \ARM\Examples \DHRY \DHRY.uv2&
& & Click &the &Options for Target button &
& & & & & & Turn off optimization settings in the Target and C/C++ tabs , then click &OK & & & & & & & & & & & & & & & &&
& & Project – &Build target&
& & Enter D ebug mode&& &&
& & View – & Se rial Windows – & UART #1&
& & & & & & & & & & & & & & & & & & & &Open the &UART #1 &window&
& & View – & Analysis Windows – & Performance Analyzer &
& & & & & & & & & & & & & & & & & & & &Open the &Performance Analyzer &
& & Debug – & Run &
& & & & & & & & & & & & & & & & & & & & &Start running the application&
& & When prompted:&
& & & & & & & & & & & & & & &Enter 50000 & in the &UART#1 & window and press Enter&
In the Performance Analyzer window, &note & that &&
o &The drhy_1 loop took 2.829s&
o &The dhry_2 took 2.014s&
In the UAR T #1 window, note &that &
o &It took 138.0 ms for 1 run through Dhrystone&
o &The application is executing 7246.4 Dhrystones per second &
Optimize the Dhrystone example for Performance &&
Re-compile the example with all three of the following optimizations applied: &
o &Options f or Target &– &Target tab: Cross - module optimization – & Remember to compile twice&
o &Options for Target – & C/C++ tab: &Optimization level 3 ( -O3)&
o &Options for Target – & C/C++ tab: &Optimize for Time&
Re-run the application, and examine the performance. &&
Measurement &Without optimizations & With Optimizations &Improvement &
dhry_1 &2.829s & 1.695s & 40.1% faster&
dhry_2 &2.014s & 1.011s & 49.8% faster&
Microseconds for 1 run&
through Dhrystone&
138.0 &70 &49.3% faster&
Dhrystones per second &7246.4 & 14,285.7 & 97.1% more &
The fu lly optimize d code achieves approximate ly 2x &the performance &of the un -optimized code.&
The ARM Compilation Tools offer a range of options to apply when compiling your code. These options can be combined to&
optimize your code for best performance, for smallest code size, or for any performance point between these two extremes, to&
best suit your targeted microcontroller device and market. & &
When optimizing your code, MDK- ARM makes it easy and convenient to measure the effect of the different optimization&
sett ings on your application. The code size is clearly displayed after compilation, and a range of analysis tools such as the&
Performance Analyzer enable you to measure performance. &
The optimization options in the ARM Compilation Tools, together with the easy- to - use analysis tools in MDK - ARM, help&
you to easily optimize your application to meet your specific requirements.&
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:258903次
积分:3382
积分:3382
排名:第8024名
原创:68篇
转载:65篇
评论:20条
(1)(4)(1)(1)(7)(13)(3)(3)(1)(2)(1)(3)(18)(1)(2)(4)(2)(6)(2)(4)(6)(4)(11)(5)(10)(2)(1)(8)(4)(3)换了好几个keil终于解决了程序编译出现bug的问题了_stm32吧_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:21,624贴子:
换了好几个keil终于解决了程序编译出现bug的问题了收藏
没写错程序但是写完程序之后出现编译错误,不同人的keil之中编译的情况不同。于是我就开始换keil来慢慢测试了。
达内stm32培训,总监级讲师签约授课,传授业内多年开发经验,点击预约和大咖面对面交流!达内stm32培训,全国40座城市,140家中心,一地学习全国推荐就业,名企高薪就业!
登录百度帐号推荐应用
为兴趣而生,贴吧更懂你。或}

我要回帖

更多关于 keil调整字体大小 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信