How to use General purpose registers in C code with MPC574x?

Showing results for 
Search instead for 
Did you mean: 

How to use General purpose registers in C code with MPC574x?

Contributor II

I am trying to port the MC33771 library which was written for S32K144(ARM architecture) to a MPC574x(Power architecture) controller. A piece of MC33771's sample code in bcc_wait.c is writtten in assembly where it waits for cycles in multiples of 4.


From the Power architecture instruction set I understand that "movs" needs to be changed to "mr" or some other equivalent instruction and "r0" can be a general-purpose register like GPR0 to GPR31.

But when I try to use GPR0-31 it throws a relocation error




1. What is the correct syntax to use the GPR registers inline with C-code?

2. What are other ways to count cycles in MPC574x? 

Thanks in advance

Labels (1)
0 Kudos
2 Replies

NXP TechSupport
NXP TechSupport


first important point: due to pipelining, flash wait states, cache, other bus masters and priorities on crossabar etc., it's not easy to generate exact delays using asm or C code. This was easy on older and simpler devices where the timing of everything was strictly given. But features which increase the performance insert relatively high variability when talking about timing.

So, my usual recommendation is: if the timing is not critical and you can accept relatively high inaccuracy, use just simple delay loops like:

for(i=0; i<delay; i++)


... or whatever like this. I can't see a benefit to write this in asm.

If the timing is critical, use a timer like PIT or STM to generate accurate delays.

Example MPC5744P STM timer S32DS Power 2017.R1 

Example MPC5744P PIT triggering interrupts GHS614 

And to asnwer your original question, here is an example of inline asm syntax (writing value 0xA1000F00 to SPR register 624 using r3 register):

    __asm("e_lis %r3, 0xA100");
    __asm("e_or2i %r3, 0x0F00");
    __asm("mtspr 624, %r3");



0 Kudos

Contributor II

Thank you lukaszadrapa‌. That was really helpful

0 Kudos