2010-02-23 155 views

回答

6

我相信你可以使用__nop內在函數。這應該編譯爲您正在構建的處理器的相應機器指令。

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

UPDATE:

下面是我剛和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 
+0

你的建議不起作用....它不編譯。 – ra170 2010-02-23 21:45:52

+0

什麼是錯誤?你是否喜歡文檔說的#include ?我用VS2008試了這個,編譯得很好。 – Dustin 2010-02-24 00:18:52

+0

嗯,好的,問題是,我不包括頭文件...感謝張貼示例代碼.. – ra170 2010-02-25 15:17:35

1

不能在64位程序中使用_asm。替換是內在的,指令列表是available here。 NOP不是其中之一,當您安裝了64位編譯器時,您必須使用MASM64,可用作vc \ bin \ x86_amd64 \ ml64.exe。

+0

好吧,但它是在C++內部,它在VC++ 2008中編譯,我不明白我想如何使用MASAM64爲此,.. – ra170 2010-02-23 21:53:46

+0

我將以另一種方式說明:如果要編譯爲x64,則不能使用_asm的內聯彙編。發佈您的_asm代碼以幫助我們爲您提供幫助。 – 2010-02-23 23:08:10