访问64位处理器寄存器(仅读取值)

时间:2015-01-12 21:47:40

标签: c++ assembly

我想知道我是否可以使用C#/ c ++读取64位寄存器的当前值,还是只能通过asm来完成?我不需要对它做任何事情,只需阅读价值。

我找到了以下代码(我知道它是32位寄存器):

int data = 0;   
__asm
{
mov ebx, 30
mov data, ebx
}
cout<<data;

但在编译之后,返回0。谢谢你的帮助。

编辑:我设法写了这样的东西:

#include <iostream>
#include <conio.h>
#include <Windows.h>
using namespace std;

extern "C" int GetValueRAX();
extern "C" int GetValueRBX();
extern "C" int GetValueRCX();
extern "C" int GetValueRDX();

int main()
{

while (!_kbhit()){

    cout << "RAX: " << GetValueRAX() << endl;
    cout << "RBX: " << GetValueRBX() << endl;
    cout << "RCX: " << GetValueRCX() << endl;
    cout << "RDX: " << GetValueRDX() << endl;
    Sleep(2000);
    system("CLS");
}

return 0;
}

然后是asm文件:

.code
GetValueRAX proc
mov rax, rax
ret
GetValueRAX endp
GetValueRBX proc
mov rax, rbx
ret
GetValueRBX endp
GetValueRCX proc
mov rax, rcx
ret
GetValueRCX endp
GetValueRDX proc
mov rax, rdx
ret
GetValueRDX endp
end

但似乎值不会刷新,因为在第一次循环调用这些过程之后,即使我同时更改了寄存器中的值,也没有任何变化。有什么建议吗?

0 个答案:

没有答案
相关问题