Mail Archives: djgpp/2002/04/08/09:30:05
Jacky Luk <luckie AT netvigator DOT com> wrote:
> "Hans-Bernhard Broeker" <broeker AT physik DOT rwth-aachen DOT de> ¼¶¼g©ó¶l¥ó·s»D
> :a8rsi9$lt$1 AT nets3 DOT rz DOT RWTH-Aachen DOT DE...
>> Jacky Luk <luckie AT netvigator DOT com> 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.
- Raw text -