I am porting existing code from Windows to Linux (Visual C++ to g++). It includes inline assembly sections.
g++ supports a compilation switch (
-masm=intel
) telling it to accept the Intel syntax instead of the AT&T one. So far so good, it should avoid painful rewriting of thousands of lines.
Anyway, there are issues with referencing the C++ variables outside the inline assembly blocks.
For instance, building
void Test()
{
int i;
asm("mov [i], 5");
...
}
results in the linker
error undefined reference to `i'
. And the assembler seems to get confused with the branching labels.
From Web searches, it seems that local variables cannot be referenced from assembly when using the Intel syntax :-(. I found several related posts, but none rescued me.
This is annoying as I can't make my variables global. (This would break multi-thread safeness and it does not seem to be compatible with namespaces).
Any hint ?