[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Stack frame



Hey alle

Jeg sidder og forsøger at finde ud af, hvordan funktionskald ser ud, og har lidt problemer med forståelsen.

Jeg har følgende funktion:
void function(void)
{
   char buffer[4];
}

Hvis jeg compiler og efterfølgende laver et dump får jeg følgende assembly kode:
08048384 <function>:
8048384: 55 push %ebp
8048385: 89 e5 mov %esp,%ebp
8048387: 83 ec 04 sub $0x4,%esp
804838a: c9 leave
804838b: c3 ret


Der bliver altså reserveret 4 bytes på stakken til mit 4 bytes lange array. Det giver jo mening.
Hvis jeg derimod laver et array på 5 bytes:


void function(void)
{
   char buffer[5];
}

...så regnede jeg med, at der blev reserveret 8 bytes (4 byte boundary), men....objdump siger følgende:
08048384 <function>:
8048384: 55 push %ebp
8048385: 89 e5 mov %esp,%ebp
8048387: 83 ec 18 sub $0x18,%esp
804838a: c9 leave
804838b: c3 ret


Altså 24 bytes. Hvordan kan det være ?
Hvorfor skal et 5 byte array fylde 24 bytes ?

Jeg prøver derefter følgende:
void function(void)
{
   int i;
   char c;
}

Altså stadig 5 bytes. Det giver følgende:
08048384 <function>:
8048384:       55                      push   %ebp
8048385:       89 e5                   mov    %esp,%ebp
8048387:       83 ec 08                sub    $0x8,%esp
804838a:       c9                      leave
804838b:       c3                      ret

Det var mine forventede 8 bytes.
Nogen der har en forklaring ?

By the way...det er en 32 bit processor og gcc version 3.3.5.

VH
Robert


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 22:44 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *