Date: Tue, 27 Jun 1995 10:59:02 -0700 To: loiselse AT ift DOT ulaval DOT ca (Sebastien Loisel) From: kbaca AT skygames DOT com (Kevin Baca) Subject: Re: Inline assembler in GCC for PC Cc: djgpp AT sun DOT soe DOT clarkson DOT edu >void SETMODE(short mode) > { > asm("mov ax,%0 \n int 10h" > : > : "f" (mode) > ); > } First, GCC asm uses AT&T op codes, not Intel. This means that source and dest operands are reversed. Try this: void SETMODE(short mode) { asm("mov %0,ax \n int 10h" : : "f" (mode) : "eax" ); } Also, notice the last colon up there. This informs the compiler that you are using the register and it can do any saving that needs to be done. An even better way to do the above would be like this: void SETMODE(short mode) { asm("int 10h" : : "a" (mode) ); } That "a" up there tells the compiler to place the variable mode in eax. Sometimes, the variable will already be in eax and the extra mov you have in your code will be avoided. Plus, in this case you don't need the extra colon at the end because the compiler already knows you're using eax. As for info, I get most of mine from the GCC info files and the asm info files. The GCC info files explain inline assembly (just search for "inline") and the asm info files explain everything else. Also, look in the farptr.h header file for examples of inline assembler AND inline functions (another useful, though non-protable, GNU extension). If you use linux, look in the string.h header file in the kernel source tree for some excellent examples of GNU inline assembly. One more thing (and this isn't explained in either doc) - the "d" that is appended to opcodes like "movsd" and "stosd" is changed to an "l" (ell) in GNU asm.