public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Passing arguments of function through registers
@ 2009-02-10 11:21 sumanth
  2009-02-10 11:28 ` Andrew Haley
  0 siblings, 1 reply; 3+ messages in thread
From: sumanth @ 2009-02-10 11:21 UTC (permalink / raw)
  To: gcc-help

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
 

 
 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-02-10 11:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-02-10 11:21 Passing arguments of function through registers sumanth
2009-02-10 11:28 ` Andrew Haley
     [not found]   ` <499165AF.6090503@redpinesignals.com>
2009-02-10 11:54     ` Andrew Haley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).