C + + | Commissioning ·? See the difference between i++ and ++i from assembly code

Source: Internet
Author: User

take int type as example C+ + compiler for + +I generated the code is 013E1375 mov eax,dword ptr [i] 013E1378 add eax,1013e137b mov dword ptr [I],eax is very simple, basically do not parse the first line is to put the value of I into EAX, and then call add to EAX+1, and finally put the eax in I and then look at I++0119137E mov eax,dword ptr [i]01191381add eax,1 01191384mov dword ptr [i],eax result is exactly the same as below and look at the case with assignmentintc = + +i;012d1384 mov eax,dword ptr [i] 012d1387 add eax,1012d138a mov dword ptr [i],eax 012d138d mov ecx,dword ptr [i] 012d1390 mov dword ptr [C],ECX Can see this operation after the completion of the first three to do two mov put the final I value in C and then seeintb = i++; 012d1375 mov eax,dword ptr [i] 012d1378 mov dword ptr [b],eax 012d137b mov ecx,dword ptr [i] 012d137e add ecx,1012d1381 mov dword ptr [I],ECX results slightly different, after putting the value of I mov to EAX and immediately put EAX into B, then the three steps remain consistent with the previous only register replaced by ECX, just in accordance with IFeatures of + +

Future CTO pays attention to my CTO's road from now on: wlaicto

C + + | Debug ·? See the difference between i++ and ++i from assembly code

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.