Newbie doubts about stack !

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

 




Hello All !

   I wrote the following C program and
obtained its assembly version , using command :

  cc -S temp.c

< on an x-86 Linux machine >

/* File Name - temp.c */

void function(int a, int b, int c) {
   char buffer[SIZE];  -------------------> SIZE=51 
}

void main() {
  function(1,2,3);
}


The Assembly File is as below :-


.file	"temp.c"
	.version	"01.01"
gcc2_compiled.:
.text
	.align 4
.globl function
	.type	 function,@function
function:
	pushl	%ebp
	movl	%esp, %ebp
	subl	$72, %esp -----------> Stack allocation
	leave
	ret
.Lfe1:
	.size	 function,.Lfe1-function
	.align 4
.globl main
	.type	 main,@function
main:
	pushl	%ebp
	movl	%esp, %ebp
	subl	$8, %esp
	subl	$4, %esp
	pushl	$3
	pushl	$2
	pushl	$1
	call	function
	addl	$16, %esp
	leave
	ret
.Lfe2:
	.size	 main,.Lfe2-main
	.ident	"GCC: (GNU) 2.96 20000731 (Red Hat Linux 7.1
2.96-81)"


In the function part of the assembly 
file , I noticed that the depending on 
the "SIZE" of the array , it allocates 
memory on stack as shown in the below
table .  

 Array Size       Actual stack allocation 

    0  - 4     =    4 
    5  - 16    =   24 
    17 - 32    =   40 
    33 - 48    =   56 
    49 - 64    =   72

Can anybody please explain me ,
what is the reason behind this ?

Why is it that only the required 
amount of stack is not allocated ?


Harmony !



________________________________________________________________________
Missed your favourite TV serial last night? Try the new, Yahoo! TV.
       visit http://in.tv.yahoo.com
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux