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)
{
    MOVQ_BFE(mm6);
    JUMPALIGN();

    do {
        __asm __volatile(
            "movq  %0, %%mm0        \n\t"
            "movq  %1, %%mm1        \n\t"
            PAVGB(%%mm0, %%mm1, %%mm2, %%mm6)
            "movq  %%mm2, %0        \n\t"
            :"+m"(*block)
            :"m"(*pixels)
            :"memory");

        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,
Khalid.
LVL 3
komarAsked:
Who is Participating?
 
mzvikaConnect With a Mentor Commented:
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:
http://vmlinux.org/crash/mirror/www.objsw.com/docs/as_196.html
http://www.w00w00.org/files/articles/att-vs-intel.txt
http://www.freepascal.org/docs-html/prog/progsu101.html
http://www.freepascal.org/docs-html/prog/progsu102.html
0
 
grg99Commented:
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.



0
 
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...
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
fridomCommented:
VS 2005 does understand inline assembler also, as you can see here:
http://msdn2.microsoft.com/en-us/library/4ks26t93(VS.80).aspx

and you could use masm to write an external assembler routine which you could link to the program
http://msdn2.microsoft.com/en-gb/library/afzk3475(VS.80).aspx

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?

Regards
Friedrich
0
 
fridomCommented:
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.

Regards
Friedrich
0
 
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.
Khalid.
0
 
mzvikaCommented:
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.
0
 
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.
0
All Courses

From novice to tech pro — start learning today.