0

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++?

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by gerard4143
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.