How to: Inline assembler in C++ (under Visual Studio 2010)

后端 未结 6 1770
孤独总比滥情好
孤独总比滥情好 2020-12-30 15:25

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

I\'d like to optimize the core using inl

6条回答
  •  佛祖请我去吃肉
    2020-12-30 16:29

    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
    }
    

    Using C or C++ in ASM blocks might be also interesting for you.

提交回复
热议问题