Looking at C + + (the circulation process) with Assembly vision

Source: Internet
Author: User

Turn from: http://blog.csdn.net/feixiaoxing/article/details/6764791

Loops are another important technique we encounter in programming. By iterating through iterations, we can get whatever results we want. Of course, there are basic conditions for such iterations, either in terms of time, or in terms of space, or as a condition of some kind of foreign interaction. There are a number of ways to cycle, but commonly used is still: while, for, Do-while, goto these several. Many of the company's projects do not like Goto, which is not to say that Goto is not good, mainly to goto the randomness is too large, once used bad, it will reduce the readability of the code, but affect the efficiency of others.

(1) Why Do-while first executes, after judgment.

As usual, let's just look at the code example and say:

View Plain 21:       int m = 10;   00401638    mov         dword ptr [ebp-4],0Ah    22:       do {   23:            printf ("%d\n",  m);   0040163f   mov          eax,dword ptr [ebp-4]   00401642    push        eax   00401643   push         offset string  "%d\n"   (0046f01c)    00401648   call        printf  (00420fb0)     0040164d   add         esp,8   24:            m ++;   00401650   mov          ecx,dword ptr [ebp-4]   00401653   add          ecx,1   00401656   mov          dword ptr [ebp-4],ecx   25:        }while (m < 10);   00401659   cmp          dword ptr [ebp-4],0Ah   0040165d    jl          process+1Fh  (0040163f)          If you replace it with a while.

View plain 21:int m = 10;   00401638 mov dword ptr [ebp-4],0ah 22:while (M <) 0040163F cmp DWORD ptr [ebp-4],14h   00401643 jge process+41h (00401661): {24:printf ("%d\n", m); 00401645 mov

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.