When you learn a compilation, you can use an disassembly tool like Ida to help you learn, and then dynamically debug with GdB or Ida to track the execution of each instruction. It's not hard.

Source: Internet
Author: User

Pan Angen
Links: https://www.zhihu.com/question/40720890/answer/87926792
Source: Know
Copyright belongs to the author. Commercial reprint please contact the author for authorization, non-commercial reprint please specify the source.

It is recommended that you first understand the format of the inline assembly of GCC, and I have not contacted GCC's inline assembly before, and are looking at Intel's compilation. Temporarily found an article GCC inline compilation basic-zhuhefang2006-chinaunix blog, learning a bit.
According to the example in the article:

<img src= "https://pic2.zhimg.com/50/a0b75d29df5a81b2666866a3f1f08158_hd.jpg" data-rawwidth= " 712 "data-rawheight=" 94 "class=" Origin_image zh-lightbox-thumb "width=" 712 "data-original=" https://pic2.zhimg.com/ A0b75d29df5a81b2666866a3f1f08158_r.jpg "> The second line of compilation in the book can be translated into Intel's:
Lea Eax,[eax+2*eax]
That is eax*3, the LEA directive is a fetch address instruction, the specific can go to check the manual, the simple is to put the right operand "[" and "]" between the value of the left operand, here is put Eax+2*eax into eax.

and the sixth Line Assembly is actually the meaning of the value pointed to by the pointer, that is, Intel compiled:
MOV Eax,[edx+4*eax]
It means taking the value of the memory address edx+4*eax and putting it in the eax. As for what this value is, we do not know, so the book also only wrote a m[...].
If you turn the mov of the last instruction into a lea:
Lea Eax,[edx+4*eax]
It means to put the value of Edx+4*eax in the EAX.

When you learn a compilation, you can use an disassembly tool like Ida to help you learn, and then dynamically debug with GdB or Ida to track the execution of each instruction. It's not hard.

When you learn a compilation, you can use an disassembly tool like Ida to help you learn, and then dynamically debug with GdB or Ida to track the execution of each instruction. It's not hard.

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.