Is it possible to access 32-bit registers in C?

C4theWin picture C4theWin · Jun 11, 2010 · Viewed 18.9k times · Source

Is it possible to access 32-bit registers in C ? If it is, how ? And if not, then is there any way to embed Assembly code in C ? I`m using the MinGW compiler, by the way. Thanks in advance!

Answer

jweyrich picture jweyrich · Jun 11, 2010

If you want to only read the register, you can simply:

register int ecx asm("ecx");

Obviously it's tied to instantiation.

Another way is using inline assembly. For example:

asm("movl %%ecx, %0;" : "=r" (value) : );

This stores the ecx value into the variable value. I've already posted a similar answer here.