016 break和Contiune语句

来源:互联网 发布:linux spi dma 编辑:程序博客网 时间:2024/05/17 09:10
/*************016 break和Contiune语句********************** * C语言精彩编程百例第16个例子 * 打印半径为1到10之间的圆的面积. */#include<stdio.h>void main(){int radius; //存放圆的半径double area; //存放圆面积for (radius=1;radius<=10;radius++){area=3.1416*radius*radius;//若圆面积超过120,则跳出for循环,不予输出if(area>=120.0)break;printf("square=%f\n",area);}//将最大圆面积的半径输出printf("now radius=%d\n\n",radius-1);for(radius=1;radius<=10;radius++){area=3.1416*radius*radius;//若面积没有超过60,则不输出而是重新开始循环if(area<120.0)continue;printf("square=%f\n",area);}printf("now radius=%d\n",radius-1);}


 对应的汇编

 

.file"016.c".def___main;.scl2;.type32;.endef.textLC2:.ascii "square=%f\12\0"LC3:.ascii "now radius=%d\12\12\0"LC4:.ascii "now radius=%d\12\0".align 8LC0:.long776530087.long1074340351.align 8LC1:.long0.long1079902208.align 2.globl _main.def_main;.scl2;.type32;.endef_main:pushl%ebpmovl%esp, %ebpsubl$24, %espandl$-16, %espmovl$0, %eaxmovl%eax, -20(%ebp)movl-20(%ebp), %eaxcall__allocacall___mainmovl$1, -4(%ebp)  # radius =1L4:cmpl$10, -4(%ebp) # radius 和 10 比较jleL7            # if radius<=10 跳jmpL5            # 退出循环L7:fildl-4(%ebp)      # 加载 radiusfldlLC0           # 加载 3.1416 // 按照在寄存器内表示方法编译器计算好了fmulp%st, %st(1)   # 31.416*radiusfildl-4(%ebp)      # 加载 radiusfmulp%st, %st(1)   # st = 31.416*radius*radiusfstpl-16(%ebp)     # area = st fldl-16(%ebp)     # area 装入stfldlLC1           # LC1 装入 st // LC1 是120.0 double类型fxch%st(1)        # 交换fucompp               # 比较fnstsw%ax           # 状态字载入axtestb$5, %ah       # 设置状态标志jeL5            # 判断条件符合则跳转出循环subl$4, %esp      # printf("square=%f\n",area)pushl-12(%ebp)pushl-16(%ebp)pushl$LC2call_printfaddl$16, %espleal-4(%ebp), %eax # eax = & radiusincl(%eax)         # radius++jmpL4             # 执行下次循环L5:subl$8, %esp       # printf("now radius=%d\n\n",radius-1)movl-4(%ebp), %eaxdecl%eaxpushl%eaxpushl$LC3call_printfaddl$16, %espmovl$1, -4(%ebp)  # radius =1L10:cmpl$10, -4(%ebp) # radius 和 10 比较jleL13           #if radius<=10 跳jmpL11           # 退出循环L13:fildl-4(%ebp)fldlLC0fmulp%st, %st(1)fildl-4(%ebp)fmulp%st, %st(1)fstpl-16(%ebp)fldl-16(%ebp)fldlLC1fucomppfnstsw%axtestb$69, %ah     # 从这里开始continue 和 break 出现差别jeL12          # 如果条件符合,跳到执行radius++处 subl$4, %esp     # 打印printf("square=%f\n",area);pushl-12(%ebp)pushl-16(%ebp)pushl$LC2call_printfaddl$16, %espL12:leal-4(%ebp), %eax # 执行radius++incl(%eax)jmpL10L11:subl$8, %esp       # printf("now radius=%d\n",radius-1);movl-4(%ebp), %eaxdecl%eaxpushl%eaxpushl$LC4call_printfaddl$16, %espleaveret.def_printf;.scl2;.type32;.endef


 

0 0
原创粉丝点击