From: devpoly AT cict DOT fr (BARDOU Jean-François) Newsgroups: comp.os.msdos.djgpp Subject: Inline ASM with DJGPP : should be more clear :) with this Date: Tue, 29 Oct 1996 13:18:29 UNDEFINED Organization: CRDP de Toulouse Lines: 102 Message-ID: NNTP-Posting-Host: pc-devpoly.cict.fr Keywords: inline asm To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp DJGPP and INLINE ASM Hello all ! I've been messing up with DGJPP inline ASM recently (3 days to understand !!), and I think I should give you what I learned :) First of all, get Brennan tutorials on ASM with DJGPP ( http://www.rt66.com/~brennan/djgpp ) It's excellent to start. Then you must know that : 1- Locals variables names are unknow in inline asm, only globals vars are. If you want to see why, try to compile your work with gcc -S myfile.c -> gives ASM version only, no link instead of gcc -o myfile.c -> gives EXE version, after link Look at your asm function: locals vars are access with (%ebp) ! (simply logical !) You should use this method (gcc -S), every time you aren't sure of the asm code you write, just to be sure DGJPP understands what you want. 2- To use locals vars in inline asm, I'll give an example: #include /* for rand */ #include /* for _dos_ds */ void fill_screen13( void) { int x, y; unsigned char col; while (!key[ KEY_ESC]) { x = rand() % 320; y = rand() % 200; col = rand() % 256; __asm__ __volatile__ (" movw %0, %%es movb %%ax, %%es:(%%edi)" : /* no outputs */ : "g" (_dos_ds), /* put _dos_ds anywhere */ "D" (0xA0000+(unsigned long)(y*320+x)), /* put offset in edi */ "a" (col) /* put col in eax */ : "eax", "edi"); /* modifie eax, edi */ } } So you can't use directly your locals vars in the inline asm, BUT you can use them in the input/output field !! 3 - To use parameters of the functions, it's the same thing : #include /* for rand */ #include /* for _dos_ds */ void putpixel13( int x, int y) { unsigned char col; col = rand() % 256; __asm__ __volatile__ (" movw %0, %%es movb %%al, %%es:(%%edi)" : /* no outputs */ : "g" (_dos_ds), /* put _dos_ds anywhere */ "a" (col), /* put col in eax */ "D" (0xA0000+(unsigned long)(y*320+x)) /* put offset in edi */ : "eax", "edi"); } This time we have mixed parameters AND locals vars. Isn't it easy ;) Conclusion - All the above examples work (for me hopefully 8) ). Now, I'm sure you have catched the feeling of the AT&T inline asm. It's really easy and it's rather like watcom inline assembly. Hope this helps, like it did for me... L8r Denis ;) /*======================================*\ || Guillemenot "DD" Denis || || Email: devpoly AT cict DOT fr || || iRC : _dd_ on #demofr, #coders || \*======================================*/