Mixing assembler and C code warning

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

Mixing assembler and C code warning

618 Views
NXP_Leo
Contributor II

In my CW11.1 project, i have many codes like below:

static void ASIL_ALU_XOR_Test(void)
{
asm ("stwu sp,-0x020(sp)");

/* Save registers*/
asm ("stw r28,0x04(sp)");
asm ("stw r29,0x08(sp)");

so when i compile the code it will report the warning like below, whether this will influence the function, if yes, how should i modify?

Description Resource Path Location Type
inline asm instruction 'STWU', defines reserved register r1. Mixing assembler and C code depends on the inline assembler not modifying the reserved registers directly. Use function level assembler if you need to directly modify the reserved registers. ASIL_ALU_Check.c /S2LS/Sources line 484 C/C++ Problem

0 Kudos
Reply
1 Reply

612 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi,

I don't think it is necessary to manually store these registers on stack.

The compiler will do that automatically. You can disassemble the function to see that all used nonvolatile registers (given by EABI standard) are stored automatically.

Simple example:

lukaszadrapa_0-1633946600919.png

This is translated as:

lukaszadrapa_1-1633946636575.png

Used r0 and r8 are volatile registers, it's not necessary to keep them. So, the stack frame is even not created here.

Now let's add this - explicitly touch r29:

lukaszadrapa_2-1633946728184.png

As you can see, r29, r30 and r31 are now put on stack:

lukaszadrapa_3-1633946806120.png

So, it doesn't make sense to do that manually again.

Regards,

Lukas

 

0 Kudos
Reply