Date: Sun, 2 Nov 1997 20:31:56 -0800 (PST) Message-Id: <199711030431.UAA13674@adit.ap.net> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" To: LEGER Patrick , djgpp AT delorie DOT com From: Nate Eldredge Subject: Re: global variable Precedence: bulk At 11:04 11/2/1997 +0100, LEGER Patrick wrote: >Here's a sample code : > >static int t; >... >void function(int x) >{ > asm("pusha > movw $_x,%eax > popa"); >} >After that the compiler say that "x" is unknown. >But if I load x in t as static and globale variable and put it into %eax >, the program runs. Correct. And when you think about it, the reason is obvious. A global or static variable is given an assembler symbol, so you can access it that way. But a local variable is accessed only as an offset in the stack frame, and it doesn't have a name in the assembly code. However, read on... >Is there a method to use directly the argument without load them in a >globale variable ? Yes. You use GCC's Extended Asm feature. See FAQ section 18.13 for pointers to more information. Here's an example of how you'd do what you want: void function(int x) { asm("pusha movw %0,%%eax # Note double percent sign! popa" : /* no output */ : "g" (x)); /* specifies an input operand */ } I'm not sure of the purpose of this code, since you store a value in eax which is immediately overwritten by the `popa'. I guess it was just a trivial example. Nate Eldredge eldredge AT ap DOT net