在64位,VS2008,C ++中替换_asm nop

时间:2010-02-23 19:30:55

标签: c++ visual-studio-2008 64-bit

如何在64位中替换_asm nop指令。编译并以32位工作。

2 个答案:

答案 0 :(得分:6)

我相信你可以使用__nop内在函数。这应编译为您正在构建的处理器的相应机器指令。

http://msdn.microsoft.com/en-us/library/aa983381(VS.80).aspx

更新:

这是我刚用VS2008创建的一个例子。它编译Win32和x64配置:

#include "stdafx.h"
#include <intrin.h>

int _tmain(int argc, _TCHAR* argv[])
{
    // The intrinsic function below will compile to a NOP machine instruction.
    // This is the same as _asm nop in the 32-bit compiler.
    __nop();
    return 0;
}

如果你想知道,我反汇编了上面的例子,x64输出是:

wmain    proc near
         db    66h
         nop
         nop
         xor   eax, eax
         retn
wmain    endp

Win32输出是:

_main    proc near
        nop
        xor    eax, eax
        retn
_main   endp

答案 1 :(得分:1)

您不能在64位程序中使用_asm。替换是内在的,指令列表是available here。 NOP不是其中之一,当您安装了64位编译器时,必须使用MASM64,可用作vc \ bin \ x86_amd64 \ ml64.exe。