Xref: news2.mv.net comp.os.msdos.djgpp:4778 From: Shawn Hargreaves Newsgroups: comp.os.msdos.djgpp Subject: Re: Inline ASM and variables Date: Sun, 9 Jun 1996 21:58:35 +0100 Organization: The University of York, UK Lines: 36 Message-ID: NNTP-Posting-Host: tower.york.ac.uk Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII In-Reply-To: <31BB2939.58D3@ix.netcom.com> To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp On Sun, 9 Jun 1996, Brian Drum wrote: > void foo(int x) { > __asm__ __volatile__ (" > movl _x, %%eax" > : > : > :"eax" ); > } > > Won't work. I get the following linker error: > test_asm.c(.text+0x4): undefined reference to `x' > > I know that I could simply have GCC load x for me but that won't do in > the more complicated things that I'm doing because I don't want to use > up a bunch of registers. Use the extended inline asm syntax, but instead of telling gcc to load x into a register (with "r", "a", "b", etc, as constraints), give gcc the option of leaving it in memory (ie. on the stack). Check the info files for details of how to use the constraints... IMHO, on the other hand, if your routine is so complicated that you need more data than will fit in registers, you are probably better off writing it in a seperate .s file rather than as inline asm. That gives a nice, clean C -> asm interface, makes life much easier if you ever want to port to other compilers, and lets you run the asm code through the C preprocessor which can be very useful. /* * Shawn Hargreaves. Why is 'phonetic' spelt with a ph? * Check out Allegro and FED on http://www.york.ac.uk/~slh100/ */