我如何使用C ++从寄存器读取值

问题描述:

我正在用C ++编写一个计算器的代码,但它显示并读取了汇编结果,我想将该值存储在任何寄存器中,例如(Al)到C ++中的int变量...我搜寻了但我总是用C语言找到它...

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

如果要将al中的值读入int:

海湾合作委员会:

unsigned char out;
asm volatile("movb %%al, %[Var]" : [Var] "=r" (out));

unsigned char out;
asm volatile("movb %%al, %0" : "=r" (out));

对于MSVC:

unsigned char c;
__asm movb c, al

没有正式的C ++方式,它源于C.

There's no official C++ way, it stems it from C.

编辑

您可能还想要:

register unsigned char out asm("%al");

但这就是海湾合作委员会.

But that's GCC.