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.
I'm using CodeBlocks pm 64-bit Windows 7 with MinGW as a compiler and I'm working on an x86-64 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
#include
#include
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;
}
No comments:
Post a Comment