views:

280

answers:

2

How to replace _asm nop instructions in 64-bit. compiles and works in 32-bit.

+1  A: 

You can't use _asm in a 64-bit program. The replacement is intrinsics, a list of instructions is available here. NOP isn't one of them, you'd have to use MASM64, available as vc\bin\x86_amd64\ml64.exe when you've got the 64-bit compilers installed.

Hans Passant
ok, but it's inside C++, it compiles in VC++ 2008, I don't understand how am I suppose to use MASAM64 for this,..
ra170
I'll put it another way: you cannot use inline assembly with _asm if you want to compile to x64. Post your _asm code to help us help you.
Hans Passant
+2  A: 

I believe that you can use the __nop intrinsic function. This should compile into the appropriate machine instruction for the processor that you are building.

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

UPDATE:

Here is an example that I just created with VS2008. It compiles for both Win32 and x64 configurations:

#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;
}

In case you are wondering, I disassembled the above example and the x64 output was:

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

The Win32 output was:

_main    proc near
        nop
        xor    eax, eax
        retn
_main   endp
Dustin
your suggestion doesn't work....it doesn't compile.
ra170
And what is the error? Did you #include <intrin.h> like the doc says? I tried this with VS2008 and it compiled fine.
Dustin
Ah, ok, the problem was that I was not including <intrin.h> header file...thanks for posting the sample code..
ra170