How do I do assembly code with the mingw-g++ compiler. All the websites I checked say that this should work:

int add(int a, int b)
{
    int c=0;
    asm("mov %[aVal],%eax;add %[bVal],%eax;mov %eax,%[cVal]"
        : [cVal] "=i" (c)
        : [bVal] "i" (b)
        : [aVal] "i" (a));
    return c;
}

But instead I get the following compiler errors:
D:\Programming\C++\test\main.cpp||In function 'int add(int, int)':|
D:\Programming\C++\test\main.cpp|10|error: expected string-literal before '[' token|
D:\Programming\C++\test\main.cpp|10|error: expected ')' before '[' token|
D:\Programming\C++\test\main.cpp|10|error: undefined named operand 'aVal'|
D:\Programming\C++\test\main.cpp|4|warning: unused parameter 'a'|
||=== Build finished: 3 errors, 1 warnings ===|

What is wrong with that code? How do I do assembly in c++?

I always thought that the GCC(mingw) compiler accepted AT&T syntax for inline assembler.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.