-mregparm option of gcc doesnt work as expected?

Programming, for all ages and all languages.
Post Reply
junkoi
Member
Member
Posts: 63
Joined: Wed Jan 23, 2008 8:55 pm

-mregparm option of gcc doesnt work as expected?

Post by junkoi »

Hi,

I have some expermentals with -mregparm option of gcc. I compile my code like this

gcc -mregparm=2 ...

So I expect that the first 2 param of a function is transferred in EAX and EDX, and from the 3rd params onward the params are put in stack. So for example calling "function(x,y,z,v)" should put "z" and "v" in stack.

But by disassembling my gcc-generated code, I surprised to see that it uses ECX for the 3rd param, and only from 4th param it uses stack. So in the above example, only "v" is in stack, but not "z" as expected (z is in ECX!!). How is that possible??

Is there any way to force gcc to use only use stack for the 3rd params onward, as it seems "-mregparm=2" didnt do what they promised?

So confused!!

I am using gcc 4.1.2 on Linux Ubuntu 7.10

Thanks,
J
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

It's possible that your test program wasn't complicated enough, and the compiler felt it could get away with optimising a little bit. Make sure you're compiling with -O0.
Post Reply