C code not generating correct assembly

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

C code not generating correct assembly

3,373 Views
ScottC
Contributor I
I am using CW and noticed code that I wrote to set a variable is being ignored, sometimes.  I looked at the assemly listing.  '08ap32
 
Any ideas?
Labels (1)
Tags (1)
0 Kudos
Reply
4 Replies

740 Views
J2MEJediMaster
Specialist I

It would help to have a look at your code and know what optimization level you're using with the compiler. When generating highly optimized code, the compiler may interpret some code is being run once and can be optimized out of existence.

 

---Tom

0 Kudos
Reply

740 Views
ScottC
Contributor I
I am just setting a global variable.  In one section of the code it is ignored.  In another, the code in the listing file is as it should be.
 
It happens to be ignored in the same in the same routine when set at different times.
 
How do I check optimization settings?

Message Edited by Scott C on 04-24-200604:47 PM

Message Edited by Scott C on 04-24-200604:53 PM

Message Edited by Scott C on 04-24-200604:54 PM

0 Kudos
Reply

740 Views
CrasyCat
Specialist III

Hello

Basically the compiler is optimizing access to global variables. If you have something like

var = 4;

var = 5;

the compiler will only generate code to assign 5 to var.

To make sure the compiler does not optimize access to a variable, define it as volatile. 

CrasyCat

0 Kudos
Reply

740 Views
ScottC
Contributor I
I just define it to pass to another routine, but I will give it a try.
 
Thanks
0 Kudos
Reply