public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: sumanth <sumanth.gundapneni@redpinesignals.com>
To: gcc-help@gcc.gnu.org
Subject: Passing arguments of function through registers
Date: Tue, 10 Feb 2009 11:21:00 -0000	[thread overview]
Message-ID: <499162C1.9020002@redpinesignals.com> (raw)

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
 

 
 

             reply	other threads:[~2009-02-10 11:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-10 11:21 sumanth [this message]
2009-02-10 11:28 ` Andrew Haley
     [not found]   ` <499165AF.6090503@redpinesignals.com>
2009-02-10 11:54     ` Andrew Haley

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=499162C1.9020002@redpinesignals.com \
    --to=sumanth.gundapneni@redpinesignals.com \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).