user1512695
user1512695

Reputation: 79

Using ASM in C++

I am using the following code:

int _tmain(int argc, _TCHAR* argv[])
{
    __asm{ 
           "MOV EAX, DMSN[0]";
           "LEA EBX, DMSN[0]";
           "CALL EBX";
         };
    return 0;
}

MOV EAX and LEA EBX, will later contain two different arrays. But as for the example they will contain the same.

I am using the following:

const BYTE DMSN[694]={blah, blah, blah};

But i am turning up with these erros:

1>c:\users\1337\documents\visual studio 2010\projects\test2\test2\test2.cpp(49): error     C2400: inline assembler syntax error in 'opcode'; found 'bad token'
1>c:\users\1337\documents\visual studio 2010\projects\test2\test2\test2.cpp(50): error     C2400: inline assembler syntax error in 'opcode'; found 'bad token'
1>c:\users\1337\documents\visual studio 2010\projects\test2\test2\test2.cpp(51): error     C2400: inline assembler syntax error in 'opcode'; found 'bad token'**strong text**

What is wrong?

Upvotes: 0

Views: 2325

Answers (2)

huseyin tugrul buyukisik
huseyin tugrul buyukisik

Reputation: 11910

if dmsn is array, you dont have to put [0] to access first element

int _tmain(int argc, _TCHAR* argv[])
{
    __asm{ 
           mov eax, DMSN
           lea ebx, DMSN
           call ebx
         };
    return 0;
}

mov instruction will automatically check for the operand sizes and will take first 32 bits into register(eax) and 32 bit effective address to register(ebx)

VC++ 2010 express

Upvotes: 1

perilbrain
perilbrain

Reputation: 8187

Your syntax is faulty, use it like this:-

 int _tmain(int argc, _TCHAR* argv[])
    {
      _asm{ 
           mov eax, DMSN[0]
           lea ebx, DMSN[0]
           call ebx
          }
        return 0;
    }

for VS based compiler.

Upvotes: 2

Related Questions