I have written a small array program in c
#include <stdio.h>
int main()
{
int arr[]={1,2,3,4,5};//int size is 4, elements 5 so size of array = 4*5 = 20
printf("%d\n", sizeof(arr));
return 0;
}
I compiled this with
gcc -O2 -fverbose-asm -S -c arr_n_pointer_confusion.c
I got this,
.section .rodata.str1.1,"aMS",@progbits,1
.LC0:
.string "%d\n"
.section .text.startup,"ax",@progbits
.p2align 4,,15
.globl main
.type main, @function
main:
.LFB22:
.cfi_startproc
pushl %ebp #
.cfi_def_cfa_offset 8
.cfi_offset 5, -8
movl %esp, %ebp #,
.cfi_def_cfa_register 5
andl $-16, %esp #,
subl $16, %esp #,
movl $20, 8(%esp) #,
movl $.LC0, 4(%esp) #,
movl $1, (%esp) #,
call __printf_chk #
xorl %eax, %eax #
leave
.cfi_restore 5
.cfi_def_cfa 4, 4
ret
.cfi_endproc
.LFE22:
.size main, .-main
.ident "GCC: (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3"
.section .note.GNU-stack,"",@progbits
Can anybody relate the steps in assembly from C. Why I am trying to do this is to understand a little the assembly code so that I can understand the difference from pointer to array.