From: "A.Appleyard" To: djgpp AT sun DOT soe DOT clarkson DOT edu Date: Tue, 15 Aug 1995 08:34:05 BST Subject: Re: inline asm? othe AT df DOT lth DOT se (Ola Theander) wrote:- > I like to know if it's possible to include asm code in the C source code > using djgpp. Here is a Gnu C(++) example:- long _ax,_bx,_cx,_dx,_si,_di,_bp,_es; short _flags; /* These swop the registers with the (values currently in _ax etc) */ #define __SR() /* save the registers */ ({asm("xchgl %eax,__ax"); \ asm("xchgl %ebx,__bx"); asm("xchgl %ecx,__cx"); asm("xchgl %edx,__dx"); \ asm("xchgl %esi,__si"); asm("xchgl %edi,__di"); asm("xchgl %ebp,__bp"); }) #define __RR() /* restore the registers */ ({ \ asm("pushf"); asm("popw __flags"); __SR();}) #define SEL _go32_info_block.selector_for_linear_memory inline void _farpokeb(uns short selector, uns long offset, uns char value) { asm("movw %0,%%fs" : : "r" (selector)); asm(".byte 0x64\n" " movb %0,(%1)" : : "r" ((uns char)value), "r" (offset));} inline void _farpokew(uns short selector, uns long offset, uns short value) { asm("movw %0,%%fs" : : "r" (selector)); asm(".byte 0x64\n" " movw %0,(%1)" : : "r" (value), "r" (offset));} inline void _farpokel(uns short selector, uns long offset, uns long value) { asm("movw %0,%%fs" : : "r" (selector)); asm(".byte 0x64\n" " movl %0,(%1)" : : "r" (value), "r" (offset));} inline uns char _farpeekb(uns short selector, uns long offset) {uns char R; asm("movw %0,%%fs" : : "r" (selector)); asm(".byte 0x64\n" " movb (%1),%0" : "=r" ((int)R) : "r" (offset)); return R;} inline uns short _farpeekw(uns short selector, uns long offset) {uns short R; asm("movw %0,%%fs" : : "r" (selector)); asm(".byte 0x64\n" " movw (%1),%0" : "=r" (R) : "r" (offset)); return R;} inline uns long _farpeekl(uns short selector, uns long offset) {uns long R; asm("movw %0,%%fs" : : "r" (selector)); asm(".byte 0x64\n" " movl (%1),%0" : "=r" (R) : "r" (offset)); return R;}