MPC565 assembly in macro #define???

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MPC565 assembly in macro #define???

2,343 Views
TanKun
Contributor I
hello ,
i use codewarrior v 5.5.1.1 for a mpc565 and want to define some asm instructions in a macro in a C head file.
the asm instructions look like :
 
   stwu     AddressInMemory,-80(AddressInMemory)
    stw       r0,8(AddressInMemory)
    mfctr    r0
    stw       r0,12(AddressInMemory)
    mfxer   r0
    stw       r0,16(AddressInMemory)   
   ....
   ....
   ....
 
which the parameter AddressInMemory is a pointer in the c program.it can be any addresse in the whole Memory.
 
i have tried to write the macro like this.
 #define portRESTORE_CONTEXT() 
  {  
  extern volatile  void * aPointer; 
     asm  ("lwz r0,32(%0)":"=g"(aPointer));
                ...
                 ...
                ...
 }
 
it not works.can someone tell me what the right is.
 
 
OR,because the assembly instructions are too much, i want write them regularly in a asm file, and define it as a assembly function, which c can also call them in C-function.but the problem is how can i give the "aPointer" of C as parameter to the assembly function,and the parameter will be given as Constant(in other words, the parameter will not use any register,because my intention is all of the contents of registers will be saved in the place where the "aPointer" points.)
 
 
 
thanks for your help.
 
kun

Message Edited by J2MEJediMaster on 2007-04-12 10:03 AM

Labels (1)
0 Kudos
Reply
1 Reply

627 Views
marc_paquette
Contributor V
Like any preprocessor macro, you need to terminate each line of a multi-line macro with a backslash. Try this:

#define portRESTORE_CONTEXT(aPointer) \
    stwu     AddressInMemory,-80(aPointer); \
    stw       r0,8(aPointer); \
    mfctr    r0; \
    stw       r0,12(aPointer); \
    mfxer   r0; \
    stw       r0,16(aPointer)

To invoke the macro, you have a couple of choices:

void f(void* p)
{
  /* C statements. */

  asm { portRESTORE_CONTEXT(p); }

  /* C statements. */
}

or

asm void a(void* p)
{
  portRESTORE_CONTEXT(p);
  blr;
}


Marc.
0 Kudos
Reply