Cygwin gcc error - asm:

I have a project written in C that originally ran on Linux, but now needs to be done on Windows. Some of the code includes this line in several places

asm("movl temp, %esp");

      

But this throws undefined reference to temp error.

This is not an issue compiling on Linux using the gcc 4.3.2 compiler (tested on another machine) which is the version I have on Cygwin. Is there any other way to accomplish what this line does?

+2


source to share


1 answer


You need to change the cygwin version from

asm("movl temp, %esp");

      

to

asm("movl _temp, %esp");

      

Yes, it is the same compiler and assembler, but they are configured differently for compatibility with the host system.

You can isolate the system-specific character prefix by simply giving gcc a specific name to use:



int *temp asm("localname");
...
__asm__("movl localname,%esp");

      

This avoids #ifs of any kind and removes the host OS dependency, but adds the compiler dependency. When talking about compiler extensions, some people write (see info as

) something like:

#ifdef __GNUC__
    __asm__("movl %[newbase],%%esp"
                :
                : [newbase] "r,m" (temp)
                : "%esp");
#else
#error haven't written this yet
#endif

      

The idea here is that this syntax allows the compiler to help you find temp

, even if it lies in the register or takes multiple instructions to load, and also to avoid conflict with you, this is the case it used the register you were knocking off. This is necessary because a simple one __asm__()

cannot be understood by the compiler.

In your case, you seem to be implementing your own streaming package, and therefore none of this matters. Gcc was not going to use% esp for calculation. (But why not just use pthreads ...?)

+3


source







All Articles