Last active
August 29, 2015 14:05
-
-
Save Azoay/ada124c128aa202307df to your computer and use it in GitHub Desktop.
if-else分岐とswitch分岐の違い
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
004011a0 <_if_test>: | |
4011a0: 55 push %ebp | |
4011a1: 89 e5 mov %esp,%ebp | |
4011a3: 83 7d 08 01 cmpl $0x1,0x8(%ebp) | |
4011a7: 75 07 jne 4011b0 <_if_test+0x10> | |
4011a9: b8 01 00 00 00 mov $0x1,%eax | |
4011ae: eb 53 jmp 401203 <_if_test+0x63> | |
4011b0: 83 7d 08 02 cmpl $0x2,0x8(%ebp) | |
4011b4: 75 07 jne 4011bd <_if_test+0x1d> | |
4011b6: b8 02 00 00 00 mov $0x2,%eax | |
4011bb: eb 46 jmp 401203 <_if_test+0x63> | |
4011bd: 83 7d 08 03 cmpl $0x3,0x8(%ebp) | |
4011c1: 75 07 jne 4011ca <_if_test+0x2a> | |
4011c3: b8 03 00 00 00 mov $0x3,%eax | |
4011c8: eb 39 jmp 401203 <_if_test+0x63> | |
4011ca: 83 7d 08 04 cmpl $0x4,0x8(%ebp) | |
4011ce: 75 07 jne 4011d7 <_if_test+0x37> | |
4011d0: b8 04 00 00 00 mov $0x4,%eax | |
4011d5: eb 2c jmp 401203 <_if_test+0x63> | |
4011d7: 83 7d 08 05 cmpl $0x5,0x8(%ebp) | |
4011db: 75 07 jne 4011e4 <_if_test+0x44> | |
4011dd: b8 05 00 00 00 mov $0x5,%eax | |
4011e2: eb 1f jmp 401203 <_if_test+0x63> | |
4011e4: 83 7d 08 06 cmpl $0x6,0x8(%ebp) | |
4011e8: 75 07 jne 4011f1 <_if_test+0x51> | |
4011ea: b8 06 00 00 00 mov $0x6,%eax | |
4011ef: eb 12 jmp 401203 <_if_test+0x63> | |
4011f1: 83 7d 08 07 cmpl $0x7,0x8(%ebp) | |
4011f5: 75 07 jne 4011fe <_if_test+0x5e> | |
4011f7: b8 07 00 00 00 mov $0x7,%eax | |
4011fc: eb 05 jmp 401203 <_if_test+0x63> | |
4011fe: b8 08 00 00 00 mov $0x8,%eax | |
401203: 5d pop %ebp | |
401204: c3 ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
00401205 <_switch_test>: | |
401205: 55 push %ebp | |
401206: 89 e5 mov %esp,%ebp | |
401208: 83 ec 10 sub $0x10,%esp | |
40120b: c7 45 fc 02 00 00 00 movl $0x2,-0x4(%ebp) | |
401212: 83 7d 08 07 cmpl $0x7,0x8(%ebp) | |
401216: 77 40 ja 401258 <_switch_test+0x53> | |
401218: 8b 45 08 mov 0x8(%ebp),%eax | |
40121b: c1 e0 02 shl $0x2,%eax | |
40121e: 05 60 30 40 00 add $0x403060,%eax | |
401223: 8b 00 mov (%eax),%eax | |
401225: ff e0 jmp *%eax | |
401227: b8 01 00 00 00 mov $0x1,%eax | |
40122c: eb 2a jmp 401258 <_switch_test+0x53> | |
40122e: b8 02 00 00 00 mov $0x2,%eax | |
401233: eb 23 jmp 401258 <_switch_test+0x53> | |
401235: b8 03 00 00 00 mov $0x3,%eax | |
40123a: eb 1c jmp 401258 <_switch_test+0x53> | |
40123c: b8 04 00 00 00 mov $0x4,%eax | |
401241: eb 15 jmp 401258 <_switch_test+0x53> | |
401243: b8 05 00 00 00 mov $0x5,%eax | |
401248: eb 0e jmp 401258 <_switch_test+0x53> | |
40124a: b8 06 00 00 00 mov $0x6,%eax | |
40124f: eb 07 jmp 401258 <_switch_test+0x53> | |
401251: b8 07 00 00 00 mov $0x7,%eax | |
401256: eb 00 jmp 401258 <_switch_test+0x53> | |
401258: c9 leave | |
401259: c3 ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int if_test(int i) { | |
if (i == 1) { | |
return 1; | |
} else if(i == 2){ | |
return 2; | |
} else if(i == 3){ | |
return 3; | |
} else if(i == 4){ | |
return 4; | |
} else if(i == 5){ | |
return 5; | |
} else if(i == 6){ | |
return 6; | |
} else if(i == 7){ | |
return 7; | |
} else { | |
return 8; | |
} | |
} | |
int switch_test(int i) { | |
int j = 2; | |
switch (i) { | |
case 1: | |
return 1; | |
case 2: | |
return 2; | |
case 3: | |
return 3; | |
case 4: | |
return 4; | |
case 5: | |
return 5; | |
case 6: | |
return 6; | |
case 7: | |
return 7; | |
defalut: | |
return 8; | |
} | |
} | |
int main(void) { | |
int i = 2; | |
if_test(i); | |
switch_test(i); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment