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]

Passing arguments of function through registers


Hi .
I successfully passed function arguments through registers in gcc-3.3.
Every thing seems okay except there is a reshuffling of registers happening once the arguments are passed in registers.


see the below example code snippet.


int add(short int x,short int y,short int z) { return x+y+z; } main() { int a=5,b=6,c=7,d; d=add(a,b,c); }

and the objdump of add function is
00000134 <_add>:
134:   c3 30           000030c3     mov        r3,r0
136:   c3 01           000001c3     mov        r0,r1
138:   c3 12           000012c3     mov        r1,r2
13a:   00 0c           00000c00     add        r0,r3,r0
13c:   80 00           00000080     add        r0,r0,r1
13e:   04 08           00000804     rts


The arguments are clearly passed in to r0,r1,r2 but my compiler reshuffled them to r3,r0,r1
my return value of a function goes to r0. since i declared r0-r3 as 1 in CALL_USED_REGISTERS ,r0-r3
are not pushed in stack.


Can any one help me to avoid the reshuffling of registers ..the idle case should be
00000134 <_add>:
134: add r0, r0,r1 ==> r0=r0+r1
138: add r0, r0, r2==> r0 = r0+r2
13c: rts


since the required values are already in r0,r1,r2.
PS: I am using gcc-3.3

Thanks,
Sumanth G






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