This is the mail archive of the gcc@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]

call insn in z80



Hi all,
 I am working for z80 port. I have the following
problem with the call insn pattern.


the code generated for the following c program is 
has got the problem.


//test.c

int (*p)(void);  //function pointer


int first_fun()
{
    return 2;

}

int main()
{
        int var;

//       var = first_fun();
        p = first_fun;
        var = p();
        return (var);
}


 I am calling the function through a function pointer
p . So, the code generator keeps, the address
of p in a register and then makes call to the
function.

  the code looks like
     
    ld  bc,_first_fun
    ld  (_p),bc
    ld  bc,(_p)
    ld  iy, bc
    call (iy)   // problem.
 but actually z80 does not have an instruction 
    call  throgh a indirect register address.

  It supports only 

	call (symbolic_address);

 So, The work I am doing in call value is
rtl pattern is 

  return \"call\\t(%1)\";


so this generates rhe wrong code.//unexpected code.


 Approach:

   So, my approach to this problem is 

     ld bc, LABEL  // push the return address
     push bc       
    ld  bc,_first_fun
    ld  (_p),bc
    ld  bc,(_p)
    ld  iy, bc
    jp  (iy)   // z80 has this mnemonic


  LABEL:

   //code

  generating code like this would solve the problem.
 But this thing I  am doing it in the call_value
 only. See in the "call_value" pattern 
 I am checking if register indirect address generate 
 the above code. otherwise retrn call\\t(%1);
 
   The extra risk is I need an additional register to
push the retrn address on to stack. (to push LABEL);


  Is this approach correct. Can I detect it 
 at an earlier stage ??

hope somebody would have patience to reach  till here.




    I am having similar doubts like this, Can I ask
these questions here.


thanks and regards

V.Brahmaiah



 











__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - Buy the things you want at great prices.
http://auctions.yahoo.com/


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