Solved

Porting assembly from MinGW to Visual Studio .NET 2005

Posted on 2007-03-22
8
878 Views
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)
{
    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.
0
Comment
Question by:komar
[X]
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
8 Comments
 
LVL 22

Expert Comment

by:grg99
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.



0
 
LVL 3

Author Comment

by:komar
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...
0
 
LVL 24

Expert Comment

by:fridom
ID: 18777942
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Accepted Solution

by:
mzvika earned 500 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:
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
 
LVL 24

Expert Comment

by:fridom
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.

Regards
Friedrich
0
 
LVL 3

Author Comment

by:komar
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.
Khalid.
0
 
LVL 5

Expert Comment

by:mzvika
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.
0
 
LVL 3

Author Comment

by:komar
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.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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…
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

749 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