Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
979 views
in Technique[技术] by (71.8m points)

assembly - how can i read value from register using C++

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...