I have the following C program:
int main()
{
int c[10] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2};
return c[0];
}
and when compiled using the -S
First of all, the x86 stack grows downwards. By convention, rbp
stores the original value of rsp
. Therefore, the function's arguments reside at positive offsets relative to rbp
, and its automatic variables reside at negative offsets. The first element of an automatic array has a lower address than all other elements, and thus is the furthest away from rbp
.
Here is a handy diagram that appears on this page:
I see no reason why the compiler couldn't use a series of push
instructions to initialize your array. Whether this would be a good idea, I am not sure.