R
ramasubramanian.rahul
hi
i was trying to see how the compiler hides the static golbals from the
linker and allows golbal varibale to be visable to the linker.i managed
to figure out how it did that ( the .lcomm and .comm sections) but the
assembly code for the c program raised a few more doubts . i am
enclosing the .c and the .s files .. if someonce could expain what the
starred statements in the .s file mean.. i would be greatful
the .c file is as follows
#include<stdio.h>
int i ;
static int j ;
int main()
{
printf ("\t%d\t%d\n" ,i , j );
}
the .s file it generated on a P4 RHEL machine using the cc command is
as follows
..file "some.c"
.section .rodata
..LC0:
.string "\t%d\t%d\n"
.text
..globl main
.type main, @function
main:
pushl %ebp
movl %esp, %ebp
subl $8, %esp * why more space in stack when no local vars
are used
andl $-16, %esp * this has something to do with making the
stack aligned to a 16 bit filed.. can u expalin it in
detail
movl $0, %eax * the next six statements make no sense to me
at all... why are they here
addl $15, %eax *
addl $15, %eax *
shrl $4, %eax *
sall $4, %eax *
subl %eax, %esp *
subl $4, %esp *
pushl j
pushl i
pushl $.LC0
call printf
addl $16, %esp
leave
ret
.size main, .-main
.comm i,4,4
.local j
.comm j,4,4
..section .note.GNU-stack,"",@progbits
.ident "GCC: (GNU) 3.4.3 20041212 (Red Hat 3.4.3-9.EL4)"
any help will be appriciated
kind regards
rahul
i was trying to see how the compiler hides the static golbals from the
linker and allows golbal varibale to be visable to the linker.i managed
to figure out how it did that ( the .lcomm and .comm sections) but the
assembly code for the c program raised a few more doubts . i am
enclosing the .c and the .s files .. if someonce could expain what the
starred statements in the .s file mean.. i would be greatful
the .c file is as follows
#include<stdio.h>
int i ;
static int j ;
int main()
{
printf ("\t%d\t%d\n" ,i , j );
}
the .s file it generated on a P4 RHEL machine using the cc command is
as follows
..file "some.c"
.section .rodata
..LC0:
.string "\t%d\t%d\n"
.text
..globl main
.type main, @function
main:
pushl %ebp
movl %esp, %ebp
subl $8, %esp * why more space in stack when no local vars
are used
andl $-16, %esp * this has something to do with making the
stack aligned to a 16 bit filed.. can u expalin it in
detail
movl $0, %eax * the next six statements make no sense to me
at all... why are they here
addl $15, %eax *
addl $15, %eax *
shrl $4, %eax *
sall $4, %eax *
subl %eax, %esp *
subl $4, %esp *
pushl j
pushl i
pushl $.LC0
call printf
addl $16, %esp
leave
ret
.size main, .-main
.comm i,4,4
.local j
.comm j,4,4
..section .note.GNU-stack,"",@progbits
.ident "GCC: (GNU) 3.4.3 20041212 (Red Hat 3.4.3-9.EL4)"
any help will be appriciated
kind regards
rahul