GCC, function call, pass arguments via push - Linux

This is a discussion on GCC, function call, pass arguments via push - Linux ; Hi, Is there a possibility to make gcc generate code that wont reserve stack at the beginning of a function and wont use this reserved piece of stack to pass arguments to another function, and will use push just before ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: GCC, function call, pass arguments via push

  1. GCC, function call, pass arguments via push

    Hi,

    Is there a possibility to make gcc generate code that wont reserve
    stack at the beginning of a function and wont use this reserved piece
    of stack to pass arguments to another function, and will use push just
    before the call instruction to do such a things?

    so i dont wanna have code like

    myfunc1:
    push %ebp
    movl %esp, %ebp
    subl ${size of (local variables + future function calls' arguments)},
    %esp
    ....
    movl {arg1}, (%esp)
    movl {arg2}, 4(%esp)
    call myfunc2
    ....

    but want to have:

    myfunc1:
    subl ${size of (just local variables)}, %esp
    ....
    movl {arg2}, %eax
    push %eax
    movl {arg1}, %eax
    push %eax
    call func2
    addl ${size of (arguments)}, %esp
    ....

    Thanks.

    --
    Best regards,
    Ivan.


  2. Re: GCC, function call, pass arguments via push

    > [I] want to have:
    >
    > myfunc1:
    > subl ${size of (just local variables)}, %esp
    > ...
    > movl {arg2}, %eax
    > push %eax
    > movl {arg1}, %eax
    > push %eax
    > call func2
    > addl ${size of (arguments)}, %esp


    That is the style used by: GCC: (GNU) 4.0.2 20051125 (Red Hat 4.0.2-8)
    at some levels of -O optimization. So, choose a previous version of gcc
    that you like. Also, investigate specifying i586 for various -mtune,
    -march, -mcpu options. Most i586 were slightly more efficient doing
    'push' than "mov ...,n(%esp)"; while for most i686 it is the opposite.
    Also, avoid SSEn because some instructions require 16-byte alignment,
    which sometimes requires more instructions or larger constants
    in order to align the stack frame at function entry and exit.

    --


+ Reply to Thread