X-Authentication-Warning: delorie.com: mailnull set sender to djgpp-bounces using -f From: Hans-Bernhard Broeker Newsgroups: comp.os.msdos.djgpp Subject: Re: Declaring variables in GAS Date: 8 Apr 2002 13:28:56 GMT Organization: Aachen University of Technology (RWTH) Lines: 42 Message-ID: References: NNTP-Posting-Host: acp3bf.physik.rwth-aachen.de Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: nets3.rz.RWTH-Aachen.DE 1018272536 9221 137.226.32.75 (8 Apr 2002 13:28:56 GMT) X-Complaints-To: abuse AT rwth-aachen DOT de NNTP-Posting-Date: 8 Apr 2002 13:28:56 GMT Originator: broeker@ To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Jacky Luk wrote: > "Hans-Bernhard Broeker" ¼¶¼g©ó¶l¥ó·s»D > :a8rsi9$lt$1 AT nets3 DOT rz DOT RWTH-Aachen DOT DE... >> Jacky Luk wrote: >> > This is the first time I get it-> >> >> You got it wrong. You were asking about a *global* variable and how >> to declare it in asm. But your C example only has a variable local to > Could you show me also how to do it with a local var.? Local variables usually won't have names, in GCC output, which is why the output given by someone else was not easy to understand. They're defined as offsets relative to the current stack or frame pointer values (%esp, %ebp). To make space for them, you move the stack pointer around. If you 'gcc -S -gstabs+', you'll find the offset used by GCC in one of the .stabs directives inserted for debugging. Here are some examples from GCC -S output of your example source: This loads 100 into 'foo1': movl $100,-4(%ebp) This reads foo1 into the EAX register: movl -4(%ebp),%eax And this is the debugging information about local variable 'foo1': .stabs "foo1:1",128,0,6,-4 The '-4' informs debuggers that foo1 is kept at ebp-4, or -4(%ebp) as found in the actual code. In human-written assembly code, you may want to define a name for this offset, and call that foo1, i.e. .equ foo1, -4 -- Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de) Even if all the snow were burnt, ashes would remain.