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.