Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am writhing code with C++ for a calculator ,but it display ead 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 ...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.0k views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...