如何在c中访问CPU寄存器?

时间:2011-05-24 09:53:52

标签: c cpu-registers

我想访问AH寄存器。我已经尝试了,但它争论asm标识符。

register int _AH asm ("AH");

平台:Intel CPU x86,Windows 7 尝试使用Visual Studio 2010(cl.exe)进行编译

3 个答案:

答案 0 :(得分:3)

我在我的项目中使用了类似的东西:

unsigned char foo;

__asm {
   mov foo, ah
}

您可以在此处获得更多信息:http://msdn.microsoft.com/en-us/library/fabdxz08.aspx

希望它有所帮助。

答案 1 :(得分:1)

您需要指定您正在使用的平台和编译器。

另外请注意,从C源代码生成的代码当然也会使用CPU的寄存器。

答案 2 :(得分:1)

在Visual Studio中,asm语法为

__asm assembly-instruction [ ; ]

__asm { assembly-instruction-list } [ ; ]

如此处http://msdn.microsoft.com/en-us/library/4ks26t93.aspx

所述