写个死循环哪个好

来源:互联网 发布:淘宝女装品牌排行榜 编辑:程序博客网 时间:2024/04/25 23:12

1://写个死循环哪个好:2://for(;;){} ?3://for(;1;){} ?4://还是while(1) ?5://Visual C++ 6.0 编译器6:7:    int main()8:    {00401010   push        ebp00401011   mov         ebp,esp00401013   sub         esp,40h00401016   push        ebx00401017   push        esi00401018   push        edi00401019   lea         edi,[ebp-40h]0040101C   mov         ecx,10h00401021   mov         eax,0CCCCCCCCh00401026   rep stos    dword ptr [edi]9:        for(;;){}00401028   jmp         main+18h (00401028)10:       for(;1;){}0040102A   mov         eax,10040102F   test        eax,eax00401031   je          main+25h (00401035)00401033   jmp         main+1Ah (0040102a)11:       while(1){}00401035   mov         ecx,10040103A   test        ecx,ecx0040103C   je          main+30h (00401040)0040103E   jmp         main+25h (00401035)12:       do{}while(1);00401040   mov         edx,100401045   test        edx,edx00401047   jne         main+30h (00401040)13:       return 0;00401049   xor         eax,eax14:   }0040104B   pop         edi0040104C   pop         esi0040104D   pop         ebx0040104E   mov         esp,ebp00401050   pop         ebp00401051   ret
使用方式生成的汇编指令条数
for(;;){}1
do{}while(1);3
for(;1;){}4
while(1){}4
结论:如果按生成汇编指令条数越少越优的话,那明显第一种方式更效率一些。
0 0
原创粉丝点击