Confusing at&t's JMP: direct jump and indirect jump

Source: Internet
Author: User
I recently looked at the source code of the linker and it has nothing to do with location. Code The link problem of PIC (shared library) found many uncommon usage of call and JMP. Here we test and summarize various usage.

The most common JMP format is the tag behind JMP! There's nothing to say!

If the label is called mylabel, its address is 0x8048377, and there is a global variable B. The content stored in B is the address of mylabel, and the address of B is 0x80494a8. There is such a value assignment (load) Statement: movl $ mylabel, % eax // load the mylabel address to the eax register movl % eax, B // load the mylabel address to movl $ B in B, % EBX // load the address of B to the EBX register. Consider the following statement: 1. jmpmylable2.jmp0x80483773. JMP % eax4.jmp * % eax5.jmp * (% EBX) 6. JMP * 0x80494a87. JMP * b8.jmp $0x5! What have they done? 1. Needless to say, I jumped to the mylabel label to continue executing the code. But how did I jump to it? That is, an offset address for JMP at the mylabel added to the PC! The executable binary code is as follows: EB 03, that is, PC + 0x03. 2. Here, 0x8048377 is the address of mylabel, which I have studied before. The function of label is equivalent to that of its address. Therefore, the execution effect here is the same as that in 1. However, there are some differences! Here the binary code is: E9 03 00 00 00 here 32 bits are used to indicate this offset, and in 1, only 8 bits are used! 3. When compiling the link, this code will have a warning: Warning: Indirect JMP '*'. The indirect jump does not have the '*' symbol. However, the execution is still correct. Take a look at the code of the binary executable file and find that a '*' number is added to it! In addition, the binary value is FF e0.4. In fact, 4 is a supplemental version of 3. the normal format is 4, and 3 is a supplemental version with a warning. 5.% EBX is the address of B, so (% EBX) indicates that the value of EBX is the address, pointing to the place. It points to the content of B, that is, the address of mylabel! Therefore, after simplification, 5 is equivalent to 2. However, the binary representation is FF 23. 6.0x80494a8 is the address of B, which is regarded as the number of memory. In essence, B points to the address of mylabel. Therefore, after simplification, it is the same as 2. the binary code is: FF 25 A8 94 04 08. 7. B is a tag that represents an address. Therefore, the binary code is the same as 6 here. 8. This sentence is incorrect. JMP does not support immediate count! Therefore, the correct statements are as follows: 1. jmpmylable // EB 032. jmp0x8048377 // E9 03 00 00 00 3. JMP * % eax // FF e04.jmp * (% EBX) // FF 235. JMP * 0x80494a8 // FF 25 A8 94 04 086. JMP * B // FF 25 A8 94 04 08 1 and 2 are called indirect addressing, which calculates the offset. There is no '*', but a tag or address (the tag can be regarded as an address). Therefore, it is a direct address value. The binary code for indirect jump is EB or E9, starting with E. 3, 4, 5, 6 is called direct addressing. The identifier of direct addressing is this! Direct addressing means that the PC directly assigns an address instead of an offset. Therefore, the part after '*' is actually a value to be paid to the PC, so the value can be imagined! The binary code for direct jump starts with ff. 3 is the direct register value; 4 is the indirect register value; 5 is the memory value; 6 is the tag value (essentially the same as 5 ). Indeed, it is a bit interesting ~ Call is the same as JMP command! [Transfer] http://gtkchen.blog.sohu.com/105685961.html

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.