如何:内联汇编在C ++(在Visual Studio 2010中) [英] How to: Inline assembler in C++ (under Visual Studio 2010)

查看:309
本文介绍了如何:内联汇编在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 ++ 可能还对你有意思。

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

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