You can use the built-in assembly with -masm = intel, as ninjalj wrote, but this can cause errors when including C / C ++ headers using the built-in assembly. This is the code for reproducing bugs in Cygwin.
sample.cpp: #include <cstdint> #include <iostream> #include <boost/thread/future.hpp> int main(int argc, char* argv[]) { using Value = uint32_t; Value value = 0; asm volatile ( "mov %0, 1\n\t" // Intel syntax // "movl $1, %0\n\t" // AT&T syntax :"=r"(value)::); auto expr = [](void) -> Value { return 20; }; boost::unique_future<Value> func { boost::async(boost::launch::async, expr) }; std::cout << (value + func.get()); return 0; }
When I built this code, I received the error messages below.
g++ -E -std=c++11 -Wall -o sample.s sample.cpp g++ -std=c++11 -Wall -masm=intel -o sample sample.cpp -lboost_system -lboost_thread /tmp/ccuw1Qz5.s: Assembler messages: /tmp/ccuw1Qz5.s:1022: Error: operand size mismatch for `xadd' /tmp/ccuw1Qz5.s:1049: Error: no such instruction: `incl DWORD PTR [rax]' /tmp/ccuw1Qz5.s:1075: Error: no such instruction: `movl DWORD PTR [rcx],%eax' /tmp/ccuw1Qz5.s:1079: Error: no such instruction: `movl %eax,edx' /tmp/ccuw1Qz5.s:1080: Error: no such instruction: `incl edx' /tmp/ccuw1Qz5.s:1082: Error: no such instruction: `cmpxchgl edx,DWORD PTR [rcx]'
To avoid these errors, it is necessary to separate the built-in assembly (upper half of the code) from the C / C ++ code, which requires boost :: future, etc. (bottom half). The -masm = intel option is used to compile .cpp files containing the built-in assembly of Intel syntax, and not for other .cpp files.
sample.hpp: #include <cstdint> using Value = uint32_t; extern Value GetValue(void); sample1.cpp: compile with -masm=intel #include <iostream> #include "sample.hpp" int main(int argc, char* argv[]) { Value value = 0; asm volatile ( "mov %0, 1\n\t" // Intel syntax :"=r"(value)::); std::cout << (value + GetValue()); return 0; } sample2.cpp: compile without -masm=intel #include <boost/thread/future.hpp> #include "sample.hpp" Value GetValue(void) { auto expr = [](void) -> Value { return 20; }; boost::unique_future<Value> func { boost::async(boost::launch::async, expr) }; return func.get(); }
Zettsu Tatsuya Jan 05 '17 at 11:11 2017-01-05 11:11
source share