本帖最后由 zcxhe 于 2010-6-22 22:04 编辑
发现STVD+Cosmic 4.3.4 unsigned char “+”运算问题!(char 也一样)给大家提个醒! 同时也希望其他同仁发现问题也给大伙提醒一下!谢谢!
volatile unsigned char tmp[3];
tmp[0]=0xdd;
tmp[1]=0xbb;
tmp[2]=0x98;
//以下运算结果是错误的
if (tmp[0]+tmp[1]==tmp[2])
{
WDR();
}
main.c:39 tmp[0]=0xdd;
0x8fa0 <main+2> 0xA6DD LD A,#0xdd LD A,#0xdd
0x8fa2 <main+4> 0x6B03 LD (0x03,SP),A LD (0x03,SP),A
main.c:40 tmp[1]=0xbb;
0x8fa4 <main+6> 0xA6BB LD A,#0xbb LD A,#0xbb
0x8fa6 <main+8> 0x6B04 LD (0x04,SP),A LD (0x04,SP),A
main.c:41 tmp[2]=0x98;
0x8fa8 <main+10> 0xA698 LD A,#0x98 LD A,#0x98
0x8faa <main+12> 0x6B05 LD (0x05,SP),A LD (0x05,SP),A
main.c:43 if (tmp[0]+tmp[1]==tmp[2])
0x8fac <main+14> 0x7B05 LD A,(0x05,SP) LD A,(0x05,SP)
0x8fae <main+16> 0x5F CLRW X CLRW X
0x8faf <main+17> 0x97 LD XL,A LD XL,A
0x8fb0 <main+18> 0x1F01 LDW (0x01,SP),X LDW (0x01,SP),X
0x8fb2 <main+20> 0x7B04 LD A,(0x04,SP) LD A,(0x04,SP)
0x8fb4 <main+22> 0x5F CLRW X CLRW X
0x8fb5 <main+23> 0x1B03 ADD A,(0x03,SP) ADD A,(0x03,SP)
0x8fb7 <main+25> 0x2401 JRNC 0x8fba JRNC 0x8fba
0x8fb9 <main+27> 0x5C INCW X INCW X
0x8fba <main+28> 0x02 RLWA X,A RLWA X,A
0x8fbb <main+29> 0x1301 CPW X,(0x01,SP) CPW X,(0x01,SP)
0x8fbd <main+31> 0x2604 JRNE 0x8fc3 JRNE 0x8fc3
main.c:45 WDR();
0x8fbf <main+33> 0x35AA50E0 MOV 0x50e0,#0xaa MOV _IWDG_KR,#0xaa
volatile unsigned char tmp[3];
tmp[0]=0xdd;
tmp[1]=0xbb;
tmp[2]=0x98;
//这样子运算才是对的!不知道从标准C语言来说是不是必须要这么做?那位专家给解释一下,谢谢!另外有没有那个网站对这一方面有详细介绍的?谢谢!
if ((unsigned char)(tmp[0]+tmp[1])==tmp[2])
{
WDR();
}
main.c:39 tmp[0]=0xdd;
0x8fa0 <main+2> 0xA6DD LD A,#0xdd LD A,#0xdd
0x8fa2 <main+4> 0x6B01 LD (0x01,SP),A LD (0x01,SP),A
main.c:40 tmp[1]=0xbb;
0x8fa4 <main+6> 0xA6BB LD A,#0xbb LD A,#0xbb
0x8fa6 <main+8> 0x6B02 LD (0x02,SP),A LD (0x02,SP),A
main.c:41 tmp[2]=0x98;
0x8fa8 <main+10> 0xA698 LD A,#0x98 LD A,#0x98
0x8faa <main+12> 0x6B03 LD (0x03,SP),A LD (0x03,SP),A
main.c:43 if ((unsigned char)(tmp[0]+tmp[1])==tmp[2])
0x8fac <main+14> 0x7B02 LD A,(0x02,SP) LD A,(0x02,SP)
0x8fae <main+16> 0x1B01 ADD A,(0x01,SP) ADD A,(0x01,SP)
0x8fb0 <main+18> 0x1103 CP A,(0x03,SP) CP A,(0x03,SP)
0x8fb2 <main+20> 0x2604 JRNE 0x8fb8 JRNE 0x8fb8
main.c:45 WDR();
0x8fb4 <main+22> 0x35AA50E0 MOV 0x50e0,#0xaa MOV _IWDG_KR,#0xaa
|
|