C code not generating correct assembly

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

C code not generating correct assembly

3,375 次查看
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?
标签 (1)
标记 (1)
0 项奖励
回复
4 回复数

742 次查看
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 项奖励
回复

742 次查看
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 项奖励
回复

742 次查看
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 项奖励
回复

742 次查看
ScottC
Contributor I
I just define it to pass to another routine, but I will give it a try.
 
Thanks
0 项奖励
回复