#include <stdio.h>

int dowhile(int n){
int i = 1;
int s = 0;
do{
s += i;
}while(i++ < n);
return s;
} int whiledo(int n){
int i = 1;
int s = 0;
while(i <= n){
s += i++;
}
return s;
} int main(int argc, char* argv[]){
printf("dowhile:%d\n", dowhile(100));
printf("while:%d\n", whiledo(100));
return 0;
}

.text:00008570 ; =============== S U B R O U T I N E =======================================
.text:00008570
.text:00008570
.text:00008570 doWhile ; CODE XREF: main+8↓p
.text:00008570 ; __unwind {
.text:00008570 MOV R2, #0
.text:00008574 MOV R3, #1 ; i = 1 s=0
.text:00008578
.text:00008578 loc_8578 ; CODE XREF: doWhile+18↓j
.text:00008578 ADD R2, R2, R3 ; s = s + i
.text:0000857C ADD R3, R3, #1 ; i++
.text:00008580 SUB R1, R3, #1 ; tmp = i -1
.text:00008584 CMP R0, R1
.text:00008588 BGT loc_8578 ; if arg0(n) > tmp continue继续循环
.text:0000858C MOV R0, R2 ; r0 为return值 r0 = s
.text:00008590 BX LR ; 使用LR的值跳转出函数
.text:00008590 ; } // starts at 8570
.text:00008590 ; End of function doWhile
.text:00008590
.text:00008594
.text:00008594 ; =============== S U B R O U T I N E =======================================
.text:00008594
.text:00008594
.text:00008594 whileDo ; CODE XREF: main+20↓p
.text:00008594 ; __unwind {
.text:00008594 SUBS R2, R0, #0
.text:00008598 MOVLE R0, #0
.text:0000859C BXLE LR ; if n <= 0 跳出函数
.text:000085A0 MOV R0, #0 ; s = 0
.text:000085A4 MOV R3, #1 ; i = 1
.text:000085A8
.text:000085A8 loc_85A8 ; CODE XREF: whileDo+20↓j
.text:000085A8 ADD R0, R0, R3 ; s += i
.text:000085AC ADD R3, R3, #1 ; i++
.text:000085B0 CMP R2, R3
.text:000085B4 BGE loc_85A8 ; if n >= i contiue
.text:000085B8 BX LR
.text:000085B8 ; } // starts at 8594
.text:000085B8 ; End of function whileDo
.text:000085B8
.text:000085BC
.text:000085BC ; =============== S U B R O U T I N E =======================================
.text:000085BC
.text:000085BC
.text:000085BC ;
.text:000085BC
.text:000085BC ; int __cdecl main(int argc, const char **argv, const char **envp)
.text:000085BC main ; CODE XREF: j_main↑j
.text:000085BC ; __unwind {
.text:000085BC PUSH {R4,LR} ; 栈上保存R4 和 LR 的值
.text:000085C0 MOV R0, #0x64 ; 'd' ; 为RO 赋值100
.text:000085C4 BL doWhile ; 跳转到doWhile。同时给LR赋值为0x85C8
.text:000085C8 MOV R1, R0
.text:000085CC LDR R0, =(aDowhileD - 0x85D8) ; 获取字符串在GOT的偏移
.text:000085D0 ADD R0, PC, R0 ; 获取字符串实际首地址
.text:000085D4 BL printf
.text:000085D8 MOV R0, #0x64 ; 'd' ; 为R0 赋值100
.text:000085DC BL whileDo ; 跳转到doWhile。同时给LR赋值为0x85E0
.text:000085E0 MOV R1, R0
.text:000085E4 LDR R0, =(aWhileD - 0x85F0) ; "while:%d\n"
.text:000085E8 ADD R0, PC, R0 ; "while:%d\n"
.text:000085EC BL printf
.text:000085F0 MOV R0, #0
.text:000085F4 POP {R4,PC}
.text:000085F4 ; End of function main
.text:000085F4
.text:000085F4 ; -----

最新文章

  1. 常用HTML标签元素结合及简介
  2. Linux下如何搭建VPN服务器(转)
  3. Linux基础知识-文件管理
  4. java连接access数据库
  5. CSS之弧形阴影
  6. CVirtualGridCtrl控件内的数据如何获取
  7. Uninstall Tool 3.3.2.5315 简体中文注册版(彻底卸载软件)
  8. AngularJS指令进阶 – ngModelController详解
  9. ceil与intval区别
  10. Map 接口简明
  11. C#中将鼠标光标变为忙碌状态
  12. maven阿里云镜像
  13. Code Sign error: Provisioning profile XXXX can&#39;t be found
  14. 关于jdbc的面试题
  15. html中radio、checkbox选中状态研究
  16. node.js常用命令
  17. Installing python-ldap in Ubuntu
  18. Spring MVC 与 CORS
  19. href中使用相对路径访问上级目录的方法
  20. 【Java】使用Eclipse进行远程调试,Linux下开启远程调试

热门文章

  1. 记一次排查线上MySQL死锁过程,不能只会curd,还要知道加锁原理
  2. NC13822 Keep In Line
  3. 论文阅读 GloDyNE Global Topology Preserving Dynamic Network Embedding
  4. Spring框架系列(12) - Spring AOP实现原理详解之JDK代理实现
  5. halcon 基础总结(一)裁切图片并旋转图像
  6. 在eclipse配置javafx
  7. jdbc 09: preparedStatement实现增删改查
  8. esp8266模拟输入(ADC)检测问题
  9. 以三元组表为存储结构实现矩阵相加(耿5.7)----------西工大 noj
  10. SkyWalking分布式系统应用程序性能监控工具-中