* Assembly - newbie doubts
@ 2002-09-04 5:56 Anticipating a Reply
2002-09-04 13:32 ` lx
0 siblings, 1 reply; 2+ messages in thread
From: Anticipating a Reply @ 2002-09-04 5:56 UTC (permalink / raw)
To: Assembly Linux
Hi All !
The following C program
was compiled using
cc -S as.c
to get the assembly instructions .
I have the doubts marked in the
assembly generated .
Please help me out with
this .Thanks in advance .
Regards!
/* C program - as.c */
void funk(int f)
{
printf("Hello");
}
main()
{
int a ;
a=10 ;
funk(a);
printf("Bye");
}
--------------------------------------------
Assembly file contents -
.file "as.c"
.version "01.01"
gcc2_compiled.:
.section .rodata
.LC0:
.string "Hello"
.text
.align 4
.globl funk
.type funk,@function
funk:
pushl %ebp
movl %esp, %ebp
subl $8, %esp ( **>'int' has 4 bytes size why 8
bytes allocated)
subl $12, %esp ( **> why 12 bytes allocated on stack
)
pushl $.LC0
call printf
addl $16, %esp
leave
ret
.Lfe1:
.size funk,.Lfe1-funk
.section .rodata
.LC1:
.string "Bye"
.text
.align 4
.globl main
.type main,@function
main:
pushl %ebp
movl %esp, %ebp
subl $8, %esp ( **>'int' has 4 bytes size why 8
bytes allocated)
movl $10, -4(%ebp) ( **> which order do the bytes go
on stack)
subl $12, %esp ( **> why 12 bytes allocated on stack
)
pushl -4(%ebp)
call funk
addl $16, %esp
subl $12, %esp ( **> why 12 bytes allocated on stack
)
pushl $.LC1
call printf
addl $16, %esp
leave
ret
.Lfe2:
.size main,.Lfe2-main
.ident "GCC: (GNU) 2.96 20000731 (Red Hat Linux 7.1
2.96-81)"
-----------------------------------------
Any documents on the related issues
will be of great help .
Thanks again
________________________________________________________________________
Want to sell your car? advertise on Yahoo Autos Classifieds. It's Free!!
visit http://in.autos.yahoo.com
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Assembly - newbie doubts
2002-09-04 5:56 Assembly - newbie doubts Anticipating a Reply
@ 2002-09-04 13:32 ` lx
0 siblings, 0 replies; 2+ messages in thread
From: lx @ 2002-09-04 13:32 UTC (permalink / raw)
To: linux-assembly
On Wed, 4 Sep 2002 06:56:45 +0100 (BST)
Anticipating a Reply <ruxyz@yahoo.com> wrote:
> /* C program - as.c */
> void funk(int f)
> {
> printf("Hello");
> }
> main()
> {
> int a ;
> a=10 ;
> funk(a);
> printf("Bye");
> }
> --------------------------------------------
> Assembly file contents -
> .file "as.c"
> .version "01.01"
> gcc2_compiled.:
> .section .rodata
> .LC0: .string "Hello"
> .text .align 4
> .globl funk
> .type funk,@function
> funk: pushl %ebp
> movl %esp, %ebp
> subl $8, %esp ( **>'int' has 4 bytes size why 8 bytes allocated)
> subl $12, %esp ( **> why 12 bytes allocated on stack )
this is not assembly but, compiled "C", so why not - if it works?
ask your compiler, and 'printf'...
> pushl $.LC0
> call printf
> addl $16, %esp
> leave
> ret
> .Lfe1:.size funk,.Lfe1-funk
> .section .rodata
> .LC1: .string "Bye"
> .text .align 4
> .globl main
> .type main,@function
> main: pushl %ebp
>>> movl %esp, %ebp
>>> subl $8, %esp ( **>'int' has 4 bytes size why 8 bytes allocated)
>>> movl $10, -4(%ebp) ( **> which order do the bytes go on stack)
>>> subl $12, %esp ( **> why 12 bytes allocated on stack )
> pushl -4(%ebp)
> call funk
GCC 'strategy', 'optimization' and, 'stack dancing', because otherwise the
program might become too fastly executing. and, what stores < pushl -4(ebp) >...
'>>>' lines just "C"-ish nonsense. try -O2 or -O3 switch to (recent) GCC.
> addl $16, %esp
> subl $12, %esp ( **> why 12 bytes allocated on stack )
^^^^^^^
-?- 16-12 = 12 -!-
> .ident "GCC: (GNU) 2.96 20000731 (Red Hat Linux 7.1 2.96-81)"
^^^^^^^^^ + ^^^
docs in gcc sources might have the answers, probably even <info gcc>.
hp
--
Linux,Assembly,Forth: http://www.lxhp.in-berlin.de/index-lx.shtml en/de
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2002-09-04 13:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-09-04 5:56 Assembly - newbie doubts Anticipating a Reply
2002-09-04 13:32 ` lx
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox