016 break和Contiune语句

/*************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;	.scl	2;	.type	32;	.endef
	.text
LC2:
	.ascii "square=%f\12\0"
LC3:
	.ascii "now radius=%d\12\12\0"
LC4:
	.ascii "now radius=%d\12\0"
	.align 8
LC0:
	.long	776530087
	.long	1074340351
	.align 8
LC1:
	.long	0
	.long	1079902208
	.align 2
.globl _main
	.def	_main;	.scl	2;	.type	32;	.endef
_main:
	pushl	%ebp
	movl	%esp, %ebp
	subl	$24, %esp
	andl	$-16, %esp
	movl	$0, %eax
	movl	%eax, -20(%ebp)
	movl	-20(%ebp), %eax
	call	__alloca
	call	___main
	movl	$1, -4(%ebp)  # radius =1
L4:
	cmpl	$10, -4(%ebp) # radius 和 10 比较
	jle	L7            # if radius<=10 跳
	jmp	L5            # 退出循环
L7:
	fildl	-4(%ebp)      # 加载 radius
	fldl	LC0           # 加载 3.1416 // 按照在寄存器内表示方法编译器计算好了
	fmulp	%st, %st(1)   # 31.416*radius
	fildl	-4(%ebp)      # 加载 radius
	fmulp	%st, %st(1)   # st = 31.416*radius*radius
	fstpl	-16(%ebp)     # area = st 
	fldl	-16(%ebp)     # area 装入st
	fldl	LC1           # LC1 装入 st // LC1 是120.0 double类型
	fxch	%st(1)        # 交换
	fucompp               # 比较
	fnstsw	%ax           # 状态字载入ax
	testb	$5, %ah       # 设置状态标志
	je	L5            # 判断条件符合则跳转出循环
	subl	$4, %esp      # printf("square=%f\n",area)
	pushl	-12(%ebp)
	pushl	-16(%ebp)
	pushl	$LC2
	call	_printf
	addl	$16, %esp
	leal	-4(%ebp), %eax # eax = & radius
	incl	(%eax)         # radius++
	jmp	L4             # 执行下次循环
L5:
	subl	$8, %esp       # printf("now radius=%d\n\n",radius-1)
	movl	-4(%ebp), %eax
	decl	%eax
	pushl	%eax
	pushl	$LC3
	call	_printf
	addl	$16, %esp
	movl	$1, -4(%ebp)  # radius =1
L10:
	cmpl	$10, -4(%ebp) # radius 和 10 比较
	jle	L13           #if radius<=10 跳
	jmp	L11           # 退出循环
L13:
	fildl	-4(%ebp)
	fldl	LC0
	fmulp	%st, %st(1)
	fildl	-4(%ebp)
	fmulp	%st, %st(1)
	fstpl	-16(%ebp)
	fldl	-16(%ebp)
	fldl	LC1
	fucompp
	fnstsw	%ax
	testb	$69, %ah     # 从这里开始continue 和 break 出现差别
	je	L12          # 如果条件符合,跳到执行radius++处 
	subl	$4, %esp     # 打印printf("square=%f\n",area);
	pushl	-12(%ebp)
	pushl	-16(%ebp)
	pushl	$LC2
	call	_printf
	addl	$16, %esp
L12:
	leal	-4(%ebp), %eax # 执行radius++
	incl	(%eax)
	jmp	L10
L11:
	subl	$8, %esp       # printf("now radius=%d\n",radius-1);
	movl	-4(%ebp), %eax
	decl	%eax
	pushl	%eax
	pushl	$LC4
	call	_printf
	addl	$16, %esp
	leave
	ret
	.def	_printf;	.scl	2;	.type	32;	.endef


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值