I have two pieces of code that are very similar. Both of the code are compiled with the `-O0` flag in AC5. When I look at the assembly of the first code, I found that some variables loaded into registers would not be stored into RAM back. As show in the figure below for pOut2, pBias, pB, pB2, and pA2.
But in the assembly of the other code, all variables loaded into registers would be stored in RAM. As show in the figure below.
I don't want the assembly code store the register values into RAM, because the `STR` instruction accupies clock cycle. I want the compiler to maximize the use of registers. How can I achieve this?
Well, you could start by using a higher optimization level than -O0...The ARM only has so many registers, and if your function has too many local variables, it won't have any choice other than to put some of them on the stack. (your pictures don't show enough of the code to see if this is what is happening, though.)
zhang yu said:I don't want the assembly code store the register values into RAM, because the `STR` instruction accupies clock cycle
If your application is really so critical that details like this matter, then you should be writing it in assembler in the first place.
zhang yu said:I want the compiler to maximize the use of registers
The compiler will do that anyway - but it may have a different view of "maximise" than you.
Again, if this level of detail really matters to you, then you should be writing it in assembler in the first place.
Thanks for your reply. What puzzled me was why the assembly code of these two pieces of code were so inconsistent. So I can't compare program performance at the -O0 option. Higher optimization does improve register utilization, and the assembly code is more consistent.
I then tried compiling again using -O0 option in AC6, at which point both pieces of code compile into assembly code that store the register values into RAM. It seems that programs compiled with AC6 are more consistent.
Thanks for your reply. Writing code in assembler is too difficult for me.
I think you should first learn the basics about compilers and assembler and ARM.
And then try different optimizations.
If you still have problems to understand what's going on, come back and ask again. But show your will to teach yourself the basics.
View all questions in Cortex-M / M-Profile forum