当前位置:网站首页>Optimization of embedded C language for indefinite cycles
Optimization of embedded C language for indefinite cycles
2022-07-27 19:37:00 【WangLanguager】
1、 Indefinite number of cycles , have access to for、while、do{}while
2、 Examples of indefinite cycles
int checksum_v6(int *data, unsigned int N)
{
int sum = 0;
for(; N != 0; N--)
{
sum += *(data++);
}
return sum;
}
The assembly code of the above program is :
checksum_v7_s
MOV r2,#0 ;sum = 0
CMP r0,#0 ; compare N,0
BEQ checksum_v7_end ; if(N == 0) goto end
checksum_v7_loop
LDR r3,[r2] #4 ;r3 = *(data++)
SUBS r1,r1,#1 ;N-- and set flags
ADD r2,r3,r2 ;sum += r3
BNE checksum_v7_loop ;if(N != 0) goto loop
checksum_v7_end
MOV r0,#r2 ;r0 = sum
MOV pc,r14 ;return r0
3、 Discuss : Generally speaking , The length of the array cannot be 0
Use do{}while Rewriting procedures :
int checksum_v8(int *data, unsigned int N)
{
int sum = 0;
do
{
sum += *(data++);
} while (--N!=0);
return sum;
}
The assembly code of the above program is :
checksum_v8_s
MOV r2,#0 ;sum = 0
checksum_v8_loop
LDR r3,[r2] #4 ;r3 = *(data++)
SUBS r1,r1,#1 ;N-- and set flags
ADD r2,r3,r2 ;sum += r3
BNE checksum_v8_loop ;if(N != 0) goto loop
MOV r0,#r2 ;r0 = sum
MOV pc,r14 ;return r0
4、 Conclusion :
Use do{}while The assembly code of the rewritten program is relatively few lines .
Use do{}while It can show better performance and code density , The premise is to ensure that the loop is executed at least once .
边栏推荐
- 一种比读写锁更快的锁,还不赶紧认识一下
- Opening and using Alibaba cloud object storage OSS
- c语言:clion调试方法
- 成本高、落地难、见效慢,开源安全怎么办?
- [Luogu p4183] cow at large P (graph theory) (tree array)
- 几种无线协议简介
- SQL server top 关键字使用
- C language: 6. Simple use and precautions of pointer
- MySQL learning notes (2) -- stored procedures and stored functions
- opds sql 里面可以用set 定义局部变量吗
猜你喜欢

kettle JVM内存设置---效果不明显

让你的聊天气泡丰富多彩

Cumulative output data of kettle Excel

redis底层数据结构详解

VMware: set up SSH

C language: 5. Multidimensional array

成本高、落地难、见效慢,开源安全怎么办?

S32K系列芯片--简介

Definition of graph traversal and depth first search and breadth first search (2)

MySQL learning notes (2) -- stored procedures and stored functions
随机推荐
mysql学习笔记(1)——变量
High cost, difficult to implement, slow to take effect, what about open source security?
HDU1573 X问题【一元线性同余方程组】
C language: 7. How to use C language multi source files
To create a MySQL data source resource group, you must choose to create a new exclusive data integration resource group? Or use a common resource group? thank you
Webmagic+selenium+chromedriver+jdbc垂直抓取数据。
js常用utils封装
Tab control of MFC advanced control (CTabCtrl)
kettle EXCEL 累计输出数据
Debian recaptured the "debian.community" domain name, but it's still not good to stop and rest
低代码实现探索(四十五)业务参数
大佬们,ORACLE CDC,本地运行,老是遇到这个An exception occurred in
C language: 9. Return in main function
C language: 5. Multidimensional array
c语言:clion调试方法
我想咨询下,我们的maxcompute spark程序需要访问redis,开发环境和生产环境redi
Responsibility should be assigned to people, and Guangzhou should take multiple measures to build a "safety line" for children in summer
c语言:5、多维数组
X-shell remote connection virtual machine
27. Basics of golang - mutex lock, read / write lock