Error: bad register name `%rax' MinGW, Windows 7, x64 CPU, C++
In my previous topic: How to read registers: RAX, RBX, RCX, RDX, RSP. RBP, RSI, RDI in C or C++? I asked about reading those registers. Now I wrote a code to read (just for now on) RAX and RBX.
Im using Windows 7 64 bit OS, CodeBlocks with MinGW as a compiler and Im working on x64 CPU. When I tried to compile the below code, I got those errors:
Error: bad register name `%rax'
Error: bad register name `%rbx'
And the code:
#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;
}
I suspect your error comes from the "clobber" line:
: "%rbx", "%rax"
which should read:
: "rbx", "rax"
(Oh, and don't ask me why!)
Edit: You will also need to compile for 64-bit, using -m64 or similar - assuming of course the MingW compiler you have is 64-bit capable in the first place.
链接地址: http://www.djcxy.com/p/85916.html上一篇: x86中没有足够的寄存器
