Pregunta

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 ...

¿Fue útil?

Solución

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.

Otros consejos

It is compiler dependent. For Intel with GCC:

//Read value from register
int x;

asm ("mov %0, AI;"
     :"=r"(x)
    );

Reference here

You mean like:

int read_register_eax()
{
    int ret;
    asm { mov [ret],eax }
    return ret;
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top