* variables
@ 2002-08-23 10:26 RCS
2002-08-24 11:54 ` variables Maciej Hrebien
0 siblings, 1 reply; 3+ messages in thread
From: RCS @ 2002-08-23 10:26 UTC (permalink / raw)
To: linux-assembly
Hi all,
Can anyone explain me how global and local variables from C are treated in
assembler?
Is that write that local variables are storage in the stack?
Thanks,
RCS.
_________________________________________________________
Oi! Você quer um iG-mail gratuito?
Então clique aqui: http://registro.ig.com.br/
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: variables
@ 2002-08-23 11:27 RCS
0 siblings, 0 replies; 3+ messages in thread
From: RCS @ 2002-08-23 11:27 UTC (permalink / raw)
To: linux-assembly
Thanks, with that command-line I could anderestand
a simple program as followed:
C-CODE
------
int a = 1;
int main(void)
{
int b = 2;
a = b;
}
ASSEMBLER CODE
--------------
.file "Variaveis.c"
.version "01.01"
gcc2_compiled.:
globl a
data
.align 4
.type a,@object
.size a,4 ; Global Variable Size Definition a (4 bytes)
a:
.long 1 ; Global Variable a = 1
text
.align 4
globl main
.type main,@function
main:
pushl %ebp
movl %esp,%ebp
subl $24,%esp
movl $2,-4(%ebp) ; Local Variable b = 2
movl -4(%ebp),%eax
movl %eax,a ; a = b
L2:
leave
ret
Lfe1:
.size main,.Lfe1-main
.ident "GCC: (GNU) 2.95.3 20010315 (release) (conectiva)"
ARE THE COMMENTS CORRECT ?
Em Aug 2002, Dmitry Trunikov escreveu:
>RCS wrote:
>
>> Can anyone explain me how global and local variables from C are treated
>in
>>assembler?
>> Is that write that local variables are storage in the stack?
>>
>Yes.
>You can compile c-program to asm-source. Try gcc -S program.c
>
>----------
_________________________________________________________
Oi! Você quer um iG-mail gratuito?
Então clique aqui: http://registro.ig.com.br/
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: variables
2002-08-23 10:26 variables RCS
@ 2002-08-24 11:54 ` Maciej Hrebien
0 siblings, 0 replies; 3+ messages in thread
From: Maciej Hrebien @ 2002-08-24 11:54 UTC (permalink / raw)
To: linux-assembly
RCS wrote:
>
> Hi all,
>
> Can anyone explain me how global and local variables from C are treated in
> assembler?
> Is that write that local variables are storage in the stack?
Global variables are likely to be placed in data segment and all local -
pushed on the stack. But i think it really depends on C compiler how it
handles all Your data. If the program is tiny, a C compiler may all Your
data push on the stack - i don't know that C standard says that all Your
global data must be placed in data segment (i suppose it doesn't say)
but it seems that it works in that way for most of programs (not
hello-like).
--
Maciej Hrebien
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2002-08-24 11:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-08-23 10:26 variables RCS
2002-08-24 11:54 ` variables Maciej Hrebien
-- strict thread matches above, loose matches on Subject: below --
2002-08-23 11:27 variables RCS
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).