View Single Post
Old May 23rd, 2006, 4:11 PM   #1
niteice
Programmer
 
niteice's Avatar
 
Join Date: Aug 2005
Posts: 98
Rep Power: 4 niteice is on a distinguished road
Send a message via AIM to niteice
GCC Inline Assembly

So I have some CPU detection code written up. It works perfectly in Visual C++, but I figured it couldn't hurt to have a version that works with GCC as well. I read up on how to properly do inline assembly in that, but everything seems to be conflicting, and the GCC manual was no help at all. It's my understanding that you need to specify which registers you modified, but no matter how I do it, I always get a syntax error. For example:
        // first, get the max cpuid level and mfg string
          __asm__ (
                "movl $0,%eax                \n\t"
                "cpuid                       \n\t"
                "movl %eax, maxLevel        \n\t"
                // now mfg string
                "movl %ebx, outID               \n\t"
                "movl %edx, (outID+4)           \n\t"
                "movl %ecx, (outID+8)           \n\t"
                "movl $0, (outID+12)            \n\t"
                : "=m" (maxLevel), "=m" (outID)
                :
                : "%eax", "%ebx", "%ecx", "%edx"
        );
(ignore potential oddities, this is my first foray into assembly and i ran it through an intel->at&t conversion script)

It looks exactly how the GCC manual states it should be. This always gives a syntax error on the ) at the end. Same thing happens with all of the other sections of assembly. Any ideas on the proper way to do this?
niteice is offline   Reply With Quote