Hello everyone,
So, I have a program I'm working on an 8051W core chip using Keil's C51 software and have a loop that looks like this:
/* If Pressure2 is saturated low*/ if ((Pressure2>>3) < (signed short)(P2SatLow)) { DAC2MSB = (unsigned char)(((P2SatLow)&0xFF00)>>8); DAC2LSB = (unsigned char)((P2SatLow)&0xFF); DAC2Error = 1; } /* If Pressure2 is saturated high */ else if ((Pressure2>>3) > (signed short)(P2SatHigh)) { DAC2MSB = (unsigned char)(((P2SatHigh)&0xFF00)>>8); DAC2LSB = (unsigned char)((P2SatHigh)&0xFF); DAC2Error = 1; }
My first case has Pressure2 saturated low so it goes through the DAC2MSB and LSB commands but then enters the DAC2Error portion in the Sat High routine. Now, from a functional standpoint, it doesn't matter, it all works out exactly the same. Regardless though, I'd like to be able to view what exactly the code is doing. I currently have optimization level 8 (which has code folding, I believe, which is what is causing it to combine these two. When I go to optimization level 7, it enters the correct DAC2Error code in the SatLow section).
Unfortunately, my code in optimization level 8 is sitting at 7.3k and I have more code to add, so I can't drop down the optimization level (well, I could for now but I'd have to remove it down the road when I add additional code). At this point, I just want to understand what the optimized version of the code looks like but I'm not sure if that's possible.
Let me know if any of you have any suggestions about how to examine this. Thanks!
Regardless though, I'd like to be able to view what exactly the code is doing.
Well, you'll have to make up your mind: either you have your cake, to look at and admire, or you eat it, to enjoy the taste.
That said, if you're really so hot on getting to see what actually happens, feel free to step through your code in the debugger's machine code view. That'll typically be a tremendous waste of time and effort, but hey, that's yours to waste, right?
This is true. It is likely to be a waste of time but who knows, I could learn a bit more about this optimization setting (though, more than likely, I think I'm going to learn to stick with opt level 7 as level 8 seems to be the main culprit of my code "thinking for itself." Heh . . .
Depending on your debugger there may be a mode that shows the ASM generated for each line of C. Is there and option to output that?
But if have code that works a t one optimization level and not another it may be a compiler bug. The compiler can optimize away a lot of things, but it still must be functionally equivalent. OR, it could be exposing a bug in your program.
But if have code that works a t one optimization level and not another it may be a compiler bug... OR, it could be exposing a bug in your program.
The latter is much more likely, of course. The language standard gives the compiler many opportunities to perform agressive optimizations. Working with a highly optimizing compiler takes some getting used to. That said, my impression is that C51 isn't exactly a highly optimizing compiler. Often the code it produces leaves a lot to be desired.
View all questions in Keil forum