Search code examples
c++visual-studio-2010visual-c++visual-c++-6visual-c++-2010

Visual Studio 2010 compiling inline assembly in c++ as if Visual Studio 6?


I have a C++ project created in VS6 that was opened in VS2010 and compiles fine. It contains a class with a bit of inline assembly including the following code:

__asm{
  mov eax,this
  mov esi,[eax].m_pImage
  ...

All fine and dandy, until I try and create a new MFC C++ project in VS2010 and add the class with the assembly code shown above. Suddenly, this will not compile as the newer interpretation of __asm requires the code to be as follows (or something similar; this compiles in any case):

__asm{
  mov eax,this
  mov esi,[eax]this.m_pImage
  ...

Now, for the life of me, I can not figure out what the difference is between the two projects which allows the converted VS6 project to compile the (presumable currently invalid) inline assembly code in VS2010, while a newly created project can't.

Is there somewhere a (hidden) setting which allows one to use the old VS6 compiler?


Solution

  • The VS6 inline ASM seems like a bug that was fixed. I say that because I am not sure how the compiler could verify that m_pImage was a member of what was loaded in the eax register and therefore could not find the offset. To answer your question, there is no way, I am aware of, to use the old ASM semantics in the VS6 compiler.

    I would make a local variable outside of the inline ASM and assign that to esi instead.

    void * pointer = this.m_pImage;
    __asm
    {
       mov ebx, pointer
       mov esi, ebx
       ...