Xref: news2.mv.net comp.os.msdos.djgpp:4467 From: Shawn Hargreaves Newsgroups: comp.os.msdos.djgpp Subject: Re: Need help with ASM sprite routine Date: Sat, 1 Jun 1996 21:10:57 +0100 Organization: The University of York, UK Lines: 51 Message-ID: NNTP-Posting-Host: tower.york.ac.uk Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII In-Reply-To: <833618156.15278.0@gememail.demon.co.uk> To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp On Sat, 1 Jun 1996, Owen wrote: > I have written a small routine to draw sprites on to bitmap images and > I have got it to work in C. I have tried rewritting the inner loop > using inline assembly but I can't get it to work. When I complie the [stuff deleted] > __asm__ __volatile__ ("pushl %%ecx \n" > "pushl %%ebx \n" > "pushl %%edi \n" > "pushl %%esi \n" > "movl %0,%%edi \n" > "movl %1,%%esi \n" > "movl %2,%%ecx \n" [stuff deleted] > : "r" (dest_data), "r" (src_data),"r" (width)); The way you are passing the parameters to the asm code is not correct. Think about it: you are telling gcc to put dest_data, src_data, and width in registers (any registers it likes), and then moving them to other registers. What would happen if it put src_data in edi? When you move %0 (the dest_data value) to %%edi it will clobber your src_data value. You can fix this by telling gcc exactly which registers you want the parameters in. Get rid of the push and move instructions at the top of the function, and change the constraints to: : "D" (dest_data), "S" (src_data), "c" (width)); "D" means put it in edi, "S" means esi, and "c" means ecx. Alternatively you could leave gcc with the choice of register, but then you should use the registers it picks throughout your function, not move them to hardcoded registers of your own, ie. your function should work entirely with the %0 and %1 values. Finally, if you need to save and restore specific registers, rather than pushing and popping the values it is easier to just add them to the clobbered list at the end of the asm statement. This way gcc will take care of them for you, but it is more efficient because they will only be saved/restored if they contain live data. /* * Shawn Hargreaves. Why is 'phonetic' spelt with a ph? * Check out Allegro and FED on http://www.york.ac.uk/~slh100/ */