【问题标题】:Getting the value at memory address X获取内存地址 X 的值
【发布时间】:2013-11-07 20:40:02
【问题描述】:

我有一个问题:如何在 c++ 中查看内存地址 X 处的数字的值。
我想做类似的东西:

mov bx, 1024d
mov ax, [bx]

来自程序集,其中 ax 将是我的结果。

感谢您的支持。
附言我刚开始使用指针和内存地址

【问题讨论】:

    标签: c++ pointers assembly x86


    【解决方案1】:

    在 C++ 中,该地址的值为*reinterpret_cast<uint16_t*>(1024)

    【讨论】:

      【解决方案2】:

      在c/c++中地址是作为指针存储的,所以你的c++代码中的BX会是

      unsigned short* _mybx = (unsigned short*)1024U; // note casting to unsigned short*
      

      要获取存储在您需要使用的地址上的值:

      unsigned short _myax = *_mybx; // note asterix here
      

      您可以使用 reinterpret_cast 代替 c 类型的演员表

      unsigned short* _bx = reinterpret_cast<unsigned short*>(1024);
      

      这是更多的c++方式

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-08-31
        • 1970-01-01
        • 2012-07-05
        • 1970-01-01
        • 2015-04-02
        • 2021-01-05
        相关资源
        最近更新 更多