在我之前的主題中:How to read registers: RAX, RBX, RCX, RDX, RSP. RBP, RSI, RDI in C or C++?我詢問了關於讀取這些寄存器的信息。現在我寫了一個代碼來閱讀(就目前來說)RAX和RBX。錯誤:錯誤的寄存器名稱'%rax'MinGW,Windows 7,x64 CPU,C++
我使用Windows 7 64位操作系統,CodeBlocks與MinGW作爲編譯器和Im在x64 CPU上工作。當我試圖編譯下面的代碼,我得到了這些錯誤:
Error: bad register name `%rax'
Error: bad register name `%rbx'
,代碼:
#include <iostream>
#include <cstdlib>
#include <stdint.h>
void read(void)
{
uint64_t rax = 0, rbx = 0;
__asm__ __volatile__ (
/* read value from rbx into rbx */
"movq %%rbx, %0;\n"
/* read value from rax into rax*/
"movq %%rax, %1;\n"
/* output args */
: "=r" (rbx), "=r" (rax)
: /* no input */
/* clear both rdx and rax */
: "%rbx", "%rax"
);
/* print out registers content */
std::cout << "RAX = " << rax << "\n";
std::cout << "RBX = " << rbx << "\n";
}
int main(int argc, char **argv)
{
read();
return 0;
}
您正在編譯我期望的32位代碼 –