Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Porting assembly from MinGW to Visual Studio .NET 2005

Posted on 2007-03-22
Medium Priority
Last Modified: 2008-01-09
Hello Experts,

I got some C code that compiles perfectly under MinGW. I tried to port the code to compile under Visual Studio .NET 2005 and was able to do that easily until I encountered some assembly code which Visual Studio .NET 2005 did not understand the way it was written. Please see an example of the assembly code i'm referring to:

static void avg_pixels8_mmx(uint8_t *block, const uint8_t *pixels, int line_size, int h)

    do {
        __asm __volatile(
            "movq  %0, %%mm0        \n\t"
            "movq  %1, %%mm1        \n\t"
            PAVGB(%%mm0, %%mm1, %%mm2, %%mm6)
            "movq  %%mm2, %0        \n\t"

        pixels += line_size;
        block += line_size;

    while (--h);

I know that the answer to this question is not made of few words. I'm OK if someone can direct me to a good tutorial that addresses porting assembly code from MinGW to MS Visual Studio compiler family. This is not the first time I deal with assembly code inside C, actually I have written some my self, but my experience in this area is all based on MS VS IDE.

Thank you,
Question by:komar
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
LVL 22

Expert Comment

ID: 18775052
I dont think you can insert MMX code  easily into a .NET program.  

Also it's quite involved to call asm code from inside a .NET program.  All the arguments have to be properly marshalled, memory has to be locked down, and plenty more.

For starters I'd rewrite it in C.  It doesnt look very comploex, just some pixel averaging.


Author Comment

ID: 18775341
Thank you grg99 for your answer. Maybe my question wasn't clear from the begining because i'm not trying to port to .NET program. All i'm trying to do is to compile the same C source under MS VS .NET IDE. The project I created for this purpose was Win32 Console application which contains only .C and .H files. I'm not trying to use the .NET framework by any means.

My problem is that if I compile the sample function shown in my question the compiles will generate many errors because it does not understand assembly the way it is written now (it is understood perfectly by MinGW as I said). for the sake of an example, __volatile is not understood by VS 2005. Similarly, "movq  %0, %%mm0" is not a valid assembly instruction from the point view of MS VS 2005, etc...
LVL 24

Expert Comment

ID: 18777942
VS 2005 does understand inline assembler also, as you can see here:

and you could use masm to write an external assembler routine which you could link to the program

You know have "just" to figure out where the differences between the assemblers are... and what the notion
%0 means. I'm not fluent in any assembler, but from the cd I'd assume that %0 means the first parameter, and it seems the order for the assembler instruction is
from-> to

So the first measn moving the content of the first parameter into the fist mmx register?

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


Accepted Solution

mzvika earned 2000 total points
ID: 18785674
actually, that's not true.
inline assembly is supported only for x86 platform, but not AMD64/x64/EM64T (pick a name). a compiler "feature".

the problem with your code is that it uses the AT&T syntax, as opposed to INTEL syntax which microsoft's compiler understands...
check these links:
LVL 24

Expert Comment

ID: 18790783
I was quite aware about where inline assembler is supported, therefor I suggested to write  a separate Assembler file with the implementation of this function. But the Assembler is for x86 so inline assembler will do the job. So it's very well true that inline Assembler is supported.


Author Comment

ID: 18792607
I was hoping for an answer that will help me do the porting in 5 minutes :-) apparently this is too much to ask for.

mzvika, you provided me with the piece of information that I was looking for which is "AT&T syntax" vs. "INTEL syntax". Now I have to learn how to port assembly between the two syntax manually.

Thank you everyone.

Expert Comment

ID: 18798539
there are tools for automatic translation, although i haven't used any of them.
try googling for them.

here is one i found: http://membres.lycos.fr/placr/a2i.html
again, i'm not recommending any of them since i'm not familiar with them.

Author Comment

ID: 18798670
I did google for translation tools and found some (including the one you listed) but non of them support translation of inline assembly. I'm now convinced that I have to do the translation manually.

Thanks again.

Featured Post

[Webinar] Protection from Cyberattacks

In this session, we’ll dive into the complexities of modern cyber threats and why only multi-vector protection can keep today’s businesses secure through the various stages of a cyberattack, across multiple vectors. Thursday September 14, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question