mike.h on Wed, 19 Feb 2003 19:44:16 -0500


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] gcc, assembly, etc...


Paul,

Thanks for giving it a shot, but as you noticed, the size of a unicode
char (2 bytes) doesn't account for it. Additional mystery provided by
the following 5 examples:

void f1(){             void f2(){             void f3(){        
  int i;                char car[5];	       char car[5];    
  char car[5];          int i;               }                 
}                      }                                  
                                               
void f4(){                      void f5(){
  char car[4];                  int a, b, c, d, e;
  char car2[4];               }
  char car3[4];
  char car4[4]; 
}

the first 2 of these functions both subtract 0x28 (40 bytes) from %ebp,
the third subtracts 0x18 (24 bytes), the fourth 0x10 (16 bytes), the
fifth 0x10 (16 bytes), and the sixth 0x14 (20 bytes). Of these, only
functions 4 and 5 behave as I expected.

On Wed, 2003-02-19 at 16:26, Paul wrote:
> See, I told you...I didn't notice this part until now.
> 
> ie. Three 5-char local arrays will need 56 bytes on the stack
> (0x38).
> 
> Paul wrote:
> 
> > I'll toss out a guess just to look stupid.  Unicode?
> >
> > mike.h wrote:
> >
> >> void function(int i){
> >>  char car[2];
> >>  return;
> >> }
> >>
> >> If I compile and disassemble this function I'll get a line like:
> >> 0x--addr-- <function+3>: sub    $0x4,%esp
> >>
> >> If I add another 2 char array, the line is unchanged, the compiler packs
> >> them both into 4 bytes, same as for 2 shorts. When I add a third it
> >> jumps to $0x8, and stays there for the 4th. If I then add a fifth, it
> >> jumps to 0xc...12 bytes, ...Similarly, if i add the line:
> >> int i; just before the array declaration, I'll get 0x8 subtracted.
> >>
> >> Now, I interpret this to mean that memory is aligned on 4 byte
> >> boundaries. However, if I change the array to char car[5]; then 0x18 (24
> >> bytes) is subtracted from %esp and all subsequent variables will
> >> subtract an additional 0x10 (16 bytes, unless they're too big to fit of
> >> course). ie. Three 5-char local arrays will need 56 bytes on the stack
> >> (0x38).
> >>
> >> Can someone explain this behavior? I'm using gcc v 3.2. TIA
> >>
> >>  
> >>
> >
> > _________________________________________________________________________
> > Philadelphia Linux Users Group        --       http://www.phillylinux.org
> > Announcements - http://lists.netisland.net/mailman/listinfo/plug-announce
> > General Discussion  --   http://lists.netisland.net/mailman/listinfo/plug
> 
> 
> _________________________________________________________________________
> Philadelphia Linux Users Group        --       http://www.phillylinux.org
> Announcements - http://lists.netisland.net/mailman/listinfo/plug-announce
> General Discussion  --   http://lists.netisland.net/mailman/listinfo/plug
-- 
-mike.h
_________________
mike.h@acm.org
mike.h@stemik.com
__________________________________________
Democracy is the worst form of government; 
except for all those other forms that have 
been tried from time to time.

-Winston Churchill
__________________________________________
GnuPG public key:
//http://www.stemik.com/~mike.h/mike.h.asc

Attachment: signature.asc
Description: This is a digitally signed message part