admin 管理员组文章数量: 1087139
2024年4月26日发(作者:个人免费建站)
18 0x08048435 <+24>: movzx eax,BYTE PTR [ebp-0x4]
19 0x08048439 <+28>: add eax,0x1
20 0x0804843c <+31>: mov BYTE PTR [ebp-0x4],al
21 0x0804843f <+34>: jmp 0x804847b
22
23 7 } else if (c == 'a' || c == 'b') {
24 0x08048441 <+36>: cmp BYTE PTR [ebp-0x4],0x61
25 0x08048445 <+40>: je 0x804844d
26 0x08048447 <+42>: cmp BYTE PTR [ebp-0x4],0x62
27 0x0804844b <+46>: jne 0x8048459
28
29 8 c += 2;
30 0x0804844d <+48>: movzx eax,BYTE PTR [ebp-0x4]
31 0x08048451 <+52>: add eax,0x2
32 0x08048454 <+55>: mov BYTE PTR [ebp-0x4],al
33 0x08048457 <+58>: jmp 0x804847b
34
35 9 } else if (c == 'A' || c == 'B') {
36 0x08048459 <+60>: cmp BYTE PTR [ebp-0x4],0x41
37 0x0804845d <+64>: je 0x8048465
38 0x0804845f <+66>: cmp BYTE PTR [ebp-0x4],0x42
39 0x08048463 <+70>: jne 0x8048471
40
41 10 c += 3;
42 0x08048465 <+72>: movzx eax,BYTE PTR [ebp-0x4]
43 0x08048469 <+76>: add eax,0x3
44 0x0804846c <+79>: mov BYTE PTR [ebp-0x4],al
45 0x0804846f <+82>: jmp 0x804847b
46
47 11 } else {
48 12 c += 4;
49 0x08048471 <+84>: movzx eax,BYTE PTR [ebp-0x4]
50 0x08048475 <+88>: add eax,0x4
51 0x08048478 <+91>: mov BYTE PTR [ebp-0x4],al
52
53 13 }
54 14
55 15 return (c);
56 0x0804847b <+94>: movsx eax,BYTE PTR [ebp-0x4]
57
58 16 }
59 0x0804847f <+98>: leave
60 0x08048480 <+99>: ret
61
62 End of assembler dump.
63 (gdb)
o 反汇编foo_switch()
1 (gdb) set disassembly-flavor intel
2 (gdb) disas /m foo_switch
3 Dump of assembler code for function foo_switch:
4 20 {
5 0x08048481 <+0>: push ebp
6 0x08048482 <+1>: mov ebp,esp
7 0x08048484 <+3>: sub esp,0x4
8 0x08048487 <+6>: mov eax,DWORD PTR [ebp+0x8]
9 0x0804848a <+9>: mov BYTE PTR [ebp-0x4],al
10
11 21 switch (c) {
12 0x0804848d <+12>: movsx eax,BYTE PTR [ebp-0x4]
13 0x08048491 <+16>: sub eax,0x30
14 0x08048494 <+19>: cmp eax,0x32
15 0x08048497 <+22>: ja 0x80484c6
16 0x08048499 <+24>: mov eax,DWORD PTR [eax*4+0x80485f0]
17 0x080484a0 <+31>: jmp eax
18
19 22 case '1':
20 23 case '0': c += 1; break;
21 0x080484a2 <+33>: movzx eax,BYTE PTR [ebp-0x4]
22 0x080484a6 <+37>: add eax,0x1
23 0x080484a9 <+40>: mov BYTE PTR [ebp-0x4],al
24 0x080484ac <+43>: jmp 0x80484d1
25
26 24 case 'b':
27 25 case 'a': c += 2; break;
28 0x080484ae <+45>: movzx eax,BYTE PTR [ebp-0x4]
29 0x080484b2 <+49>: add eax,0x2
30 0x080484b5 <+52>: mov BYTE PTR [ebp-0x4],al
31 0x080484b8 <+55>: jmp 0x80484d1
32
33 26 case 'B':
34 27 case 'A': c += 3; break;
35 0x080484ba <+57>: movzx eax,BYTE PTR [ebp-0x4]
版权声明:本文标题:为什么switchcase语句比ifelse执行效率高 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/b/1714098792a665609.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论