Using AT&T syntax on x86-64, I wish to assemble c = a + b; as
add %[a], %[b], %[c]
Unfortunately, GNU's assembler will not do it. Why not?
DETAILS
According to Intel's Software Developer's Manual, rev. 75 (June 2021), vol. 2, section 2.5,
VEX-encoded general-purpose-register instructions have ... instruction syntax support for three encodable operands.
The VEX prefix is an AVX feature, so x86-64 CPUs from Sandy Bridge/Bulldozer onward implement it. That's ten years ago, so GNU's assembler ought to assemble my three-operand instruction, oughtn't it?
To clarify, I am aware that one can write it in the old style as
mov %[a], %[c]
add %[b], %[c]
However, I wish to write it in the new, VEX style. Incidentally, I have informed the assembler that I have a modern CPU by issuing GCC the -march=skylake command-line option.
What is my mistake, please?
SAMPLE CODE
In a C++ wrapper,
#include <cstddef>
#include <iostream>
int main()
{
volatile int a{8};
volatile int b{5};
volatile int c{0};
//c = a + b;
asm volatile (
//"mov %[a], %[c]\n\t"
//"add %[b], %[c]\n\t"
"add %[a], %[b], %[c]\n\t"
: [c] "=&r" (c)
: [a] "r" (a), [b] "r" (b)
: "cc"
);
std::cout << c << "\n";
}