问题
I am writhing code with C++ for a calculator ,but it display\read results with assembly,I want to store the value in any register for example( Al )to variable int in C++... I searched for away but I always find it with C language ...
回答1:
If you want to read value in al into an int:
GCC:
unsigned char out;
asm volatile("movb %%al, %[Var]" : [Var] "=r" (out));
Or
unsigned char out;
asm volatile("movb %%al, %0" : "=r" (out));
For MSVC:
unsigned char c;
__asm movb c, al
There's no official C++ way, it stems it from C.
EDIT
You might also want:
register unsigned char out asm("%al");
But that's GCC.
回答2:
It is compiler dependent. For Intel with GCC:
//Read value from register
int x;
asm ("mov %0, AI;"
:"=r"(x)
);
Reference here
回答3:
You mean like:
int read_register_eax()
{
int ret;
asm { mov [ret],eax }
return ret;
}
来源:https://stackoverflow.com/questions/19895038/how-can-i-read-value-from-register-using-c