Skip to main content
roar
Associate II
December 15, 2022
Solved

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

  • December 15, 2022
  • 1 reply
  • 1482 views

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?

This topic has been closed for replies.
Best answer by Tesla DeLorean

Generate a listing file and inspect it?​

1 reply

Tesla DeLorean
Tesla DeLoreanBest answer
Guru
December 15, 2022

Generate a listing file and inspect it?​

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
roar
roarAuthor
Associate II
December 15, 2022

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?

Tesla DeLorean
Guru
December 15, 2022

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

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