昏昏暗暗 2022-10-29 22:57 采纳率: 81%
浏览 30
已结题

C++的cin指令反汇编问题出现了转移的目的地址在内存中的问题?

int main(void)
{
    int n;
    int x;
    cin >> n; //这个cin在反汇编中的call使用的是转移的目的地址在内存中,
                   //而且ecx对象也是用转移的目的地址在内存中
    for (int i = 0; i < n; n++) //请问这是为什么?这个 call 转移的目的地址在内存
                                        //中 在C++中是什么代码使用的?
    {
        cin >> x;
    }

    return 0;
}

img

  • 写回答

3条回答 默认 最新

  • _GX_ 2022-10-31 19:19
    关注

    你可以使用undname命令把C++ mangled name进行demangle,以便于阅读。下面是你图中标注的两个符号的demangled name。

    C:\> undname "?cin@std@@3V?$basic_istream@DU?$char_traits@D@std@@@1@A"
    Microsoft (R) C++ Name Undecorator
    Copyright (C) Microsoft Corporation. All rights reserved.
    
    Undecoration of :- "?cin@std@@3V?$basic_istream@DU?$char_traits@D@std@@@1@A"
    is :- "class std::basic_istream<char,struct std::char_traits<char> > std::cin"
    
    C:\>undname "??5?$basic_istream@DU?$char_traits@D@std@@@std@@QAEAAV01@AAH@Z"
    Microsoft (R) C++ Name Undecorator
    Copyright (C) Microsoft Corporation. All rights reserved.
    
    Undecoration of :- "??5?$basic_istream@DU?$char_traits@D@std@@@std@@QAEAAV01@AAH@Z"
    is :- "public: class std::basic_istream<char,struct std::char_traits<char> > & __thiscall std::basic_istream<char,struct std::char_traits<char> >::operator>>(int &)"
    

    因此,上面汇编代码的意思就是把std::cin的地址拷贝到ECX寄存器中,然后调用std::cin::operator>>(int&)函数。注意这个函数采用__thiscall调用规则,即this指针采用ECX寄存器传递,而参数int&则是前面push eax通过栈传递的。

    https://en.wikipedia.org/wiki/X86_calling_conventions#thiscall

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 11月11日
  • 已采纳回答 11月3日
  • 赞助了问题酬金15元 10月30日
  • 创建了问题 10月29日

悬赏问题

  • ¥15 对于知识的学以致用的解释
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败