Porting assembly from MinGW to Visual Studio .NET 2005

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,
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.

komarAuthor Commented:
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...
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?

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

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:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.

komarAuthor Commented:
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.
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.
komarAuthor Commented:
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.