我可以通过拆卸来了解地址吗? [英] Can I know address from dis assembling

查看:136
本文介绍了我可以通过拆卸来了解地址吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi guys, I use g cc. I want to know the address of each and every line of code.Is there any way obtaining it through dis assembling? the first column of dis assembled output seems like address to me, but I am not sure.

    #include <stdio.h>
    #include <string.h>

    int main()
    {
        char name[20],address[500];
        printf("enter your name::: \n");
        fgets(name, sizeof(name), stdin);
        printf("name you entered is:: %s \n", name);
        printf("enter your name::: \n");
        fgets(address, sizeof(address), stdin);
        printf("address you entered is:: %s \n", address);
    }
for above example I want to know address at each and every line.

推荐答案

地址一段代码通常由链接器而不是编译器确定。您在汇编程序代码清单中看到的是程序相对地址。链接器将组合来自各种编译单元的代码,然后构造可执行文件或dll。即使在加载dll的那一刻,如果存在与其他dll的冲突,也可能将其重新定位到不同的地址。



如果查看反汇编的代码在运行时,例如在调试器中,您实际上可能会看到代码所在的最终地址。



但是在编译器优化代码时要注意可以自由地混合来自各种代码行的指令。一行代码可能会分布在代码的大部分内容中,并且会散布其他行的代码。
The address of a piece of code is usually determined by the linker, not the compiler. What you see in an assembler code listing is a procedure relative address. The linker will combine the code from the various compilation units and then construct the executable or dll. And even in the moment when a dll is loaded, it might be relocated to a different address if a conflict with other dlls exists.

If you look at the disassembled code at runtime, for example in a debugger, then you might in fact see the final addresses where your code is located.

But be warned, when optimizing the code the compiler takes the freedom to mix instruction from various code lines. A single line of code might be spread over a large part of the code and interspersed with the code of other lines .


这篇关于我可以通过拆卸来了解地址吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆