017 exit()函数
2015-01-21 13:49
169 查看
/*************************017.c exit()函数************************ * C 语言编程百例的第17个例子: *输入月数,程序打印出1999年的该月有几天。 */ #include<stdlib.h> #include<stdio.h> void main() { //定义变量month和day存放月数和天数 int month; int day; printf("please input the month number:"); scanf("%d",&month); switch(month) { //当输入为1、3、5、7、8、10和12月时: case 1: case 3: case 5: case 7: case 8: case 10: case 12: day=31; break; //每天天数都是31天,跳出循环 //当输入为4、6、9、和11月时 case 4: case 6: case 9: case 11: day=30; break; //每天都是30天,跳出循环 case 2: day=28; break; default: exit(0); } printf("1999.%d has %d days.\n",month,day); }
使用如下编译器:
对应的汇编
.file "017.c" .def ___main; .scl 2; .type 32; .endef .text .align 32 LC0: .ascii "please input the month number:\0" LC1: .ascii "%d\0" LC2: .ascii "1999.%d has %d days.\12\0" .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, -12(%ebp) movl -12(%ebp), %eax call __alloca call ___main subl $12, %esp #printf("please input the month number:"); pushl $LC0 call _printf addl $16, %esp subl $8, %esp #scanf("%d",&month); leal -4(%ebp), %eax pushl %eax pushl $LC1 call _scanf addl $16, %esp cmpl $12, -4(%ebp) # month和12 比 ja L28 # 大于调到 exit(0) movl -4(%ebp), %eax # eax=month sall $2, %eax # eax =eax* 4 (跳转编号4位对其) movl L29(%eax), %eax # eax = L29:%eax jmp *%eax .p2align 2 .align 4 L29: .long L28 .long L22 .long L27 .long L22 .long L26 .long L22 .long L26 .long L22 .long L22 .long L26 .long L22 .long L26 .long L22 L22: movl $31, -8(%ebp) jmp L15 L26: movl $30, -8(%ebp) jmp L15 L27: movl $28, -8(%ebp) jmp L15 L28: subl $12, %esp #调用exit函数, pushl $0 call _exit #退出程序 L15: subl $4, %esp pushl -8(%ebp) pushl -4(%ebp) pushl $LC2 call _printf addl $16, %esp leave ret .def _exit; .scl 2; .type 32; .endef .def _scanf; .scl 2; .type 32; .endef .def _printf; .scl 2; .type 32; .endef
相关文章推荐
- 使用C++异常来取代exit()函数
- Window关机函数ExitWindowsEx详解
- exit(0)函数
- 关于perl中Exit的函数使用
- 警告:隐式声明与内建函数'exit'不兼容解决方案
- exit()函数详解与Exit() 和 Return() 的区别
- exit函数使用造车内存泄漏问题
- Window关机函数ExitWindowsEx详解
- ExitWindowsEx()函数的相关用法
- Linux中pthread_exit函数设置是否合理?
- algo1-4.cpp 说明exit()函数作用的程序
- 几个出错处理的函数abort、exit、atexit、strerror函数的使用方法
- [导入]php exit 函数的一个Notice
- exit()函数详解与Exit() 和 Return() 的区别
- 挑战30天C++入门极限-exit()与return()函数的差别
- 中止脚本执行函数:exit()和die()
- exit()函数详解与Exit() 和 Return() 的区别
- Exit()函数
- Windows下stdlib.h与glut.h中exit()函数重复定义的解决方案
- Exit()函数