When will CCR.V be set? Could you give an example?

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

When will CCR.V be set? Could you give an example?

跳至解决方案
1,775 次查看
fqh
Contributor II

The MCU is MC9S12ZVCA96, and the IDE is codewarrior 10.7.

We need to check the overflow bit CCR.V after an addition operation.

There is no intrinsic function for CCR.V checking. So we can't let the compiler to generate BVC/BVS instruction except assembly language.

 

0 项奖励
回复
1 解答
1,738 次查看
lama
NXP TechSupport
NXP TechSupport

Hi,

yes you can do any of ASM branch instructions or you can use following code and then work with C and defined variable. The OV test is not a standard function because it would require  application SW reaction. It would enter additional code which is usually not necessary. This must be handled by app. engineer which also leads him to think about used variables ranges.

//================= GLOBAL VARIABLES ===================================
unsigned char CCRbackup;  // temp variable to store CCRL, byte because CCRL is only used
//================= MACROS ==========================================

// save CCR to variable CCRbackup ... reg. D0 is used as an information carrier
#define getCCR() { asm PSH D0;   asm TFR CCL,D0;   asm ST D0, CCRbackup;   asm PUL D0; }

//==================================================================
// Main
//==================================================================
void main(void)
{
  //------------------------
  // example of reading CCR start, the CCR is tored into the global variable CCRbackup
  //------------------------
  getCCR();                              // the CCRL is stored in the CCRbackup variable
  //------------------------

 

Best regards,

Ladislav

在原帖中查看解决方案

1 回复
1,739 次查看
lama
NXP TechSupport
NXP TechSupport

Hi,

yes you can do any of ASM branch instructions or you can use following code and then work with C and defined variable. The OV test is not a standard function because it would require  application SW reaction. It would enter additional code which is usually not necessary. This must be handled by app. engineer which also leads him to think about used variables ranges.

//================= GLOBAL VARIABLES ===================================
unsigned char CCRbackup;  // temp variable to store CCRL, byte because CCRL is only used
//================= MACROS ==========================================

// save CCR to variable CCRbackup ... reg. D0 is used as an information carrier
#define getCCR() { asm PSH D0;   asm TFR CCL,D0;   asm ST D0, CCRbackup;   asm PUL D0; }

//==================================================================
// Main
//==================================================================
void main(void)
{
  //------------------------
  // example of reading CCR start, the CCR is tored into the global variable CCRbackup
  //------------------------
  getCCR();                              // the CCRL is stored in the CCRbackup variable
  //------------------------

 

Best regards,

Ladislav

%3CLINGO-SUB%20id%3D%22lingo-sub-1963925%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ECCR.V%20%E4%BD%95%E6%97%B6%E8%AE%BE%E7%BD%AE%EF%BC%9F%E4%BD%A0%E8%83%BD%E4%B8%BE%E4%B8%AA%E4%BE%8B%E5%AD%90%E5%90%97%EF%BC%9F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1963925%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EMCU%E4%B8%BAMC9S12ZVCA96%EF%BC%8CIDE%E4%B8%BAcodewarrior%2010.7%E3%80%82%3C%2FP%3E%3CP%3E%E6%88%91%E4%BB%AC%E9%9C%80%E8%A6%81%E5%9C%A8%E5%8A%A0%E6%B3%95%E8%BF%90%E7%AE%97%E5%90%8E%E6%A3%80%E6%9F%A5%E6%BA%A2%E5%87%BA%E4%BD%8DCCR.V%E3%80%82%3C%2FP%3E%3CP%3E%E6%B2%A1%E6%9C%89%E7%94%A8%E4%BA%8E%20CCR.V%20%E6%A3%80%E6%9F%A5%E7%9A%84%E5%86%85%E5%9C%A8%E5%87%BD%E6%95%B0%E3%80%82%E6%89%80%E4%BB%A5%E6%88%91%E4%BB%AC%E4%B8%8D%E8%83%BD%E8%AE%A9%E7%BC%96%E8%AF%91%E5%99%A8%E7%94%9F%E6%88%90%E9%99%A4%E6%B1%87%E7%BC%96%E8%AF%AD%E8%A8%80%E4%B9%8B%E5%A4%96%E7%9A%84BVC%2FBVS%E6%8C%87%E4%BB%A4%E3%80%82%3C%2FP%3E%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E