Click here to Skip to main content
15,892,059 members

Inline assembly with the Intel syntax, linking to local variables

YvesDaoust asked:

Open original thread
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
C++
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 ?
Tags: ASM, g++, Intel

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900