Date: Mon, 19 Jan 1998 12:26:41 -0800 (PST) Message-Id: <199801192026.MAA04264@adit.ap.net> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" To: "elizabeth anne dominy" , djgpp AT delorie DOT com From: Nate Eldredge Subject: Re: Strange errors after calling an ASM routine Precedence: bulk At 06:37 1/18/1998 GMT, elizabeth anne dominy wrote: >Hi, > >I have a routine that loads data from disk into an array of chars (variable >size) that works properly as far as I can tell. The thing is I have another >routine that clears the graphics screen, and uses the following ASM code >(looped if I have to clear more than one bank, depending on screen mode, NB >not working with VBE2.0+) -- > >__asm__ __volatile__ (" > movw %0,%%es > movl $0,%%edi > movw $65535, %%cx > movb $0,%%al > rep > stosb >" : : "g" (graphics_selector) : "memory"); > >After calling this routine, or in fact any ASM routine, simple assignment >such as > > f1 = f2; //both are structs of the same type > >cause Segmentation Violation Exceptions! Any ideas why? You need to tell GCC what registers you have clobbered, and you need to explicitly save and restore %es. Fixed version: asm volatile("movw %%es, %%dx ;" /* I don't use `push' and `pop' because of a problem with -fomit-frame-pointer */ "movw %0,%%es ;" "xorl %%edi, %%edi ;" /* faster/smaller than movl $0,... */ "movw $65535,%%cx ;" "rep; stosb ;" "movw %%dx,%%es" : : "g" (graphics_selector) : "cx", "dx", "edi", "memory"); Nate Eldredge eldredge AT ap DOT net