#1010 PUSH would be better for storing function's arguments to sta

gcc (462)

GCC version: 3.4.5 (mingw special)
LD version: 2.15.91 20040904
OS version: Windows XP Professional
mingw run-time version: 3.9
w32api version: 3.6

GCC in MinGW generates code that uses MOV instructions (two per arg.) to store function's arguments to stack. It would be better to use PUSH instruction to store arguments, beacuse it results in smaller code.

Compile "bug.c" (I use "gcc bug.c -o bug.exe").
In output .exe file the piece of code for calling the function "function" is:

0040130F A1 90404000 MOV EAX,DWORD PTR DS:[404090] //Load value
00401314 894424 04 MOV DWORD PTR SS:[ESP+4],EAX //Store to stack
00401318 A1 80404000 MOV EAX,DWORD PTR DS:[404080]
0040131D 890424 MOV DWORD PTR SS:[ESP],EAX
00401320 E8 BBFFFFFF CALL 004012E0 //Call function

This code would be better (i.e. smaller):

PUSH DWORD ptr DS:[404090]
PUSH DWORD ptr DS:[404080]
CALL 004012E0


  • Libor Kadlcik

    Libor Kadlcik - 2007-02-17

    Demonstration code calling a function

  • Danny Smith

    Danny Smith - 2007-02-17

    Logged In: YES
    Originator: NO

    Please read the gcc documentation on -maccumulate-outgoing-args (which is on by default with -mtune=-i686) and -mpush-args.

    You can override the defaults if you like. Or take your case to the gcc developers on the gcc mailing list


  • Danny Smith

    Danny Smith - 2007-02-17
    • status: open --> closed-wont-fix
  • Earnie Boyd

    Earnie Boyd - 2013-01-23
    • status: closed-wont-fix --> closed
    • resolution: --> wont-fix
    • category: --> Known_Feature
    • milestone: Known_Feature --> OTHER

Log in to post a comment.