如何在C ++中进行内联汇编(Visual Studio 2010) [英] How to do inline assembly in C++ (Visual Studio 2010)

查看:51
本文介绍了如何在C ++中进行内联汇编(Visual Studio 2010)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个对性能至关重要的数字运算C ++项目,其中200%的核心模块使用了70%的时间.

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

我想使用内联汇编来优化内核,但是我对此是全新的.但是,我确实知道一些x86汇编语言,包括GCC和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 ++ 对于你.

这篇关于如何在C ++中进行内联汇编(Visual Studio 2010)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆