如何:内联汇编在C ++(在Visual Studio 2010中)

问题描述:

我写的,其中70%的时间用在200行核心模块性能关键,数字运算C ++项目。

I'm writing a performance-critical, number-crunching C++ project where 70% of the time is used by the 200 line core module.

我想用最优化内联汇编的核心,但我完全新本。我这样做,不过,知道一些x86汇编语言,包括海湾合作委员会和NASM所使用的。

I'd like to optimize the core using inline assembly, but I'm completely new to this. I do, however, know some x86 assembly languages including the one used by GCC and NASM.

我所知道的:

我必须把 _asm汇编指令{} ,我想他们是。

I have to put the assembler instructions in _asm{} where I want them to be.

问题:


  • 我不知道从哪里开始。在其注册的那一刻我什么内联汇编进场?

您可以通过其名称访问变量,并将它们复制到寄存器。
下面是从MSDN的例子:

You can access variables by their name and copy them to registers. Here's an example from MSDN:

int power2( int num, int power )
{
   __asm
   {
      mov eax, num    ; Get first argument
      mov ecx, power  ; Get second argument
      shl eax, cl     ; EAX = EAX * ( 2 to the power of CL )
   }
   // Return with result in EAX
}

使用ASM块C或C ++ 可能还对你有意思。