A Survey...

Who here uses inline assembly?

Originally posted by MrShoe:
Who here uses inline assembly?

I have been known to. Why do you ask?

And what sort of inline assembly are you interested in? I’ve dabbled some under VC++ (and therefore obviously x86). I think OpenGL just begs for you to do your own stuff with SSE (since GLfloats are single-precision)

Well, I need some help and I cant find it on Google… This is a rather simple question… what is the C syntax for inline assembly. My book doesnt have it and the stuff I find on the net doesnt seem to work. I use DevC++ 4.0 This is my code:

#include <stdio.h>
#include <stdlib.h>

int main(void){
asm("
MOV AH,02
MOV DL,"!"
INT 21h
MOV AH,04Ch
MOV AL,00
INT 21h
");
system(“PAUSE”);
return 0;
}

It complains there is a parse error before !
I then change it to:

#include <stdio.h>
#include <stdlib.h>

int main(void){
asm("
MOV AH,02
MOV DL,’!’
INT 21h
MOV AH,04Ch
MOV AL,00
INT 21h
");
system(“PAUSE”);
return 0;
}
And it gives me a load of error relating to
c:\windows emp\ccwnfggb.s
saying stuff like too many references for mov
Can you help?

How you do inline assembly varies depending on which compiler you use. Dev C++ uses the gcc compiler. Check out the documentation for that. I think gcc uses AT&T assembly syntax which is different from the Intel syntax most examples you’ll see will use. I don’t really know any assembler so I can’t help you more than that, sorry.

Originally posted by harsman:
Dev C++ uses the gcc compiler. Check out the documentation for that.

I’ve never even heard of Dev C++, but if it does use gcc, here are some links I have hanging around that might be handy:

http://www-106.ibm.com/developerworks/linux/library/l-ia.html
http://www.uwsg.indiana.edu/hypermail/linux/kernel/9804.2/0953.html
http://www.delorie.com/gnu/docs/gcc/gcc_86.html

Hope they help!

Here are some concrete examples that work with gcc… seeing examples always makes thing easier, I think.

#define fsqrt(f)
({float _f = (f), _ans; asm (“fsqrt” : “=t” (_ans) : “0” (_f)); _ans;})

#define fsin(a)
({float _a = (a), _s; asm (“fsin” : “=t” (_s) : “0” (_a)); _s;})

#define fcos(a)
({float _a = (a), _c; asm (“fcos” : “=t” (_c) : “0” (_a)); _c;})

#define fabs(f)
({float _f = (f), _ans; asm (“fabs” : “=t” (_ans) : “0” (_f)); _ans;})

#define fsincos(a, s, c)
{
float _a = (a);
float _s = (s);
float _c = (c);

asm (“fsincos”
: “=t” (
_c), “=u” (
_s)
: “0” (_a));
}

class fvector
{
public:
float x;
float y;
float z;
float w;

fvector(float _x, float _y, float _z, float _w)
        : x(_x), y(_y), z(_z), w(_w)
    {}
fvector()
    {}

fvector operator+(const fvector &v1)
    {
        fvector ret __attribute__((aligned(16)));

#if defined USE_SSE
asm volatile(“movl %1, %%esi ;”
“movl %2, %%edi ;”
“movaps (%%esi), %%xmm0 ;”
“addps (%%edi), %%xmm0 ;”
“movaps %%xmm0, %0 ;”
: “=m” (ret) : “m” (this), “m” (&v1));
#else
ret.x = x + v1.x;
ret.y = y + v1.y;
ret.z = z + v1.z;
ret.w = w + v1.w;
#endif // USE_SSE

        return ret;
    }

} attribute((aligned(16)));

Hope that helps.

Oh, I didnt know it used AT&T form, that will probably fix things, thanks!