cancel
Showing results for 
Search instead for 
Did you mean: 

How can we check that the compiler use ASR and not LSR?

roar
Associate II

Below is a copy of a warning found within the PID-controller of MC-SDK 5.Y.4.

We have a Cortext-M4 based board so I guess the warning text is a copy-paste and I should not care that it mentions Cortex-M3..

    /* WARNING: the below instruction is not MISRA compliant, user should verify
               that Cortex-M3 assembly instruction ASR (arithmetic shift right)
               is used by the compiler to perform the shifts (instead of LSR
               logical shift right)*/
    //cstat !MISRAC2012-Rule-1.3_n !ATH-shift-neg !MISRAC2012-Rule-10.1_R6

How can we check if the compiler uses ASR and not LSR in these situations?

1 ACCEPTED SOLUTION

Accepted Solutions

Generate a listing file and inspect it?​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

3 REPLIES 3

Generate a listing file and inspect it?​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Thanks for the reply.

Never inspected a listing file, but did my best.

First, found the STM32 Cortext-M4 Programming Manual (PM0214) and looked up Arithmetic Shift Right in the Instruction Set table (Table 21). Further read the reference chapter for that instruction.

In the listing file, I found a section for PI_Controller function and copied it for simplicity's sake to a new editor. Searching for both ASR and LSR. Comparing the lines for ASR with the PM0214 tells me that ASR is used some places, although my experience with assembly code is zero so I cannot relate the specific line in listing file with actual C code. My search for LSR ended up with zero hits.

Is it correctly of me to assume that the function uses ASR for the specific shift operation?

This MISRA caution is about making a definitive determination, the danger is in making assumptions.​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..