This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: call stack's order of parameters


Hi all,

What are the rules of a call stack regarding the order
in which parameters are placed? Program 1 creates the
call stack (pointer to "HELLO", pointer to
"ANDRE_KIRCHNER", 0xFF), while Program 1 creates the
call stack (pointer to "ANDRE_KIRCHNER", pointer to
"HELLO", 0xFF).

Thanks in advance,

Andre

##############################################################
program1.c:
##############################################################
#include <stdio.h>

void function(char * sentenceA, char * sentenceB, int
number)
{

}

int main()
{
   function("ANDRE_KIRCHNER", "HELLO", 0xFF);

   return 0;
}

##############################################################
program1.s
##############################################################

        .file   "main.c"
        .text
.globl function
        .type   function, @function
function:
        pushl   %ebp
        movl    %esp, %ebp
        popl    %ebp
        ret
        .size   function, .-function
        .section        .rodata
.LC0:
        .string "HELLO"
.LC1:
        .string "ANDRE_KIRCHNER"
        .text
.globl main
        .type   main, @function
main:
        leal    4(%esp), %ecx
        andl    $-16, %esp
        pushl   -4(%ecx)
        pushl   %ebp
        movl    %esp, %ebp
        pushl   %ecx
        subl    $12, %esp
        movl    $255, 8(%esp)
        movl    $.LC0, 4(%esp)
        movl    $.LC1, (%esp)
        call    function
        movl    $0, %eax
        addl    $12, %esp
        popl    %ecx
        popl    %ebp
        leal    -4(%ecx), %esp
        ret
        .size   main, .-main
        .ident  "GCC: (GNU) 4.1.2 20070626 (Red Hat
4.1.2-13)"
        .section        .note.GNU-stack,"",@progbits

##############################################################
CALL STACK 1:
##############################################################
40
36
32
28
24
20
16 .LC0  <-%esp ("HELLO")
12 .LC1         ( "ANDRE_KIRCHNER")
 8 0xFF
 4
 0       <-%ebp

##############################################################
program2.c
##############################################################
#include <stdio.h>

void function(char * sentenceA, char * sentenceB, int
number)
{

}

int main()
{
   char * sentenceA = "ANDRE_KIRCHNER";
   char * sentenceB = "HELLO";

   function(sentenceA, sentenceB, 0xFF);

   return 0;
}

##############################################################
program2.s
##############################################################
        .text
.globl function
        .type   function, @function
function:
        pushl   %ebp
        movl    %esp, %ebp
        popl    %ebp
        ret
        .size   function, .-function
        .section        .rodata
.LC0:
        .string "ANDRE_KIRCHNER"
.LC1:
        .string "HELLO"
        .text
.globl main
        .type   main, @function
main:
        leal    4(%esp), %ecx
        andl    $-16, %esp
        pushl   -4(%ecx)
        pushl   %ebp
        movl    %esp, %ebp
        pushl   %ecx
        subl    $28, %esp
        movl    $.LC0, -12(%ebp)
        movl    $.LC1, -8(%ebp)
        movl    $255, 8(%esp)
        movl    -8(%ebp), %eax
        movl    %eax, 4(%esp)
        movl    -12(%ebp), %eax
        movl    %eax, (%esp)
        call    function
        movl    $0, %eax
        addl    $28, %esp
        popl    %ecx
        popl    %ebp
        leal    -4(%ecx), %esp
        ret
        .size   main, .-main
        .ident  "GCC: (GNU) 4.1.2 20070626 (Red Hat
4.1.2-13)"
        .section        .note.GNU-stack,"",@progbits

##############################################################
CALL STACK 2:
##############################################################
40
36
32
28 .LC0  <-%esp ("ANDRE_KIRCHNER")
24 .LC1         ("HELLO")
20 0xFF
16
12 .LC0
 8 .LC1
 4
 0       <-%ebp



       
____________________________________________________________________________________
Need a vacation? Get great deals
to amazing places on Yahoo! Travel.
http://travel.yahoo.com/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]