|
Blue Forest http://www.lslnet.com at 10:18 on June 6, 2006
Under stack allocation of gcc [code]#include "Stdio.h>;
Int main (int argc, char* argv[])
{
Int X :
Char buf[10];
X=8;
Buf[0]= 'a';
Buf[1]= '\0';
Return;
}[/code]
LINUX look at the assembly code is as follows :
[code]1 : Push %ebp
2 : Romov %esp %ebp
3 : sub $ 0x28 %esp
4 : $ 0xfffffff0 and %esp
%eax Romov 0x0 : $ 5
6 : sub %eax %esp
7 : Romov %0x8 12 (%ebp)
8 : -40 Romov %0x61 (%ebp)
9 : Romov %0x0 -39 (%ebp)
10 : leave
11 : ret[/code]
I do not understand is :
(1) Why are here to allocate 40 (0x28) bytes of space, accounting for four int bytes, buf accounted for 10 bytes, this is the case, even if it took 16 byte alignment, the result can only allocate 24 bytes ah?
(2) under the code, I understand the following allocation of the Stack
+------+
- - ┈ ┈ ┈ ┈ the main ebp
├──────┤
- - -------------8 Useless bytes of space
+------+
- - -----4 Bytes of int variable x
├──────┤
- - -----18 Useless bytes of space
+------+
- - ------10 Bytes of buf
├──────┤
Low address
Ask, I have no understanding of the above ah?
If no wrong, then why variable x, and they are not linked together buf? Instead, use any intermediate space?
(3) The above compilation of code, the first five - or six firms are doing what is the use? |
Under stack allocation of gcc -0 (%ebp) -- Return address
4 (%ebp) - argv
8 (%ebp) ---- argc
12 (%ebp) ----x
. . . . Buff
Calling the case when you consider the function parameters. |
Under stack allocation of gcc TO renstone921
And argc, argv not.
You see main1 (), the compilation is the same :
[code]
#include "Stdio.h>;
Int main1 ()
{
Int X :
Char buf[10];
X=8;
Buf[0]= 'a';
Buf[1]= '\0';
Return;
}
Main ()
{
Main1 ();
}
[/code] |
Under stack allocation of gcc -->
Argc, argv is so spread? |
Under stack allocation of gcc Confused
See answers to the |
Under stack allocation of gcc Alignment is required, the compiler will be opened up to greater than the actual variable alignment is consistent with the size of the back room. In less than where it idle.
[code]
Main1 ()
{
Char buf[N];
Buf[0] = 'A';
}
[/code]
N [17,32] GROUPS ---> 40 distribution
[33,48] --》56
[49, X -->74
[9,16] -->24 (You still have x, plus 16 bytes ====== 40)
And so on.
Different compiler, the compiler option would be different. |
Under stack allocation of gcc -->
Why has it required months x 16 bytes? |
Under stack allocation of gcc 2 x (int x, x) is 16. It is to stay out behind the variable (Alignment) space |
Under stack allocation of gcc Sorry, wrong, the recipients.
To think one gram :
It means you look at what is the size range, the length of each interval is 16, then increase the maximum interval 8, which is in line with the handling of 16-byte alignment? |
Under stack allocation of gcc
| Under stack allocation of gcc What is not clear how the GCC (no need to know).
You can experiment engage up with the precise function.
What can find code? |
Under stack allocation of gcc It is estimated that some `` smart gcc '' algorithm may look at the code can understand. |
Under stack allocation of gcc -->
Since it is so, then the question becomes : I now known compiler and the compiler of the following parameters, how to set a function to analyze the function of the amount allocated in the stack space? (For example, in tacit gcc compiler parameter below) |
Under stack allocation of gcc I think there might be translated option, we will optimize the trial opened again? |
Under stack allocation of gcc Should have nothing to do with optimization |
Under stack allocation of gcc
| |
|