Hi all,
I got a strange problem when I change the runtime model to large data memory model.
The C code that can be used to reproduce the problem is shown below:
void main(void)
{
char *ptr;
WDTCTL = WDTPW+WDTHOLD; // Disable WDT
/*
* Following lines behave correctly.
* The code won't jump into the if statement.
*/
ptr = (char *)0x2E000;
if(ptr >= ((char *)(0x2E600)))
{
ptr = (char *)0x22000;
}
/*
* Following lines behave incorrectly.
* The code will jump into the if statment, which shouldn't happen!
*/
ptr = (char *)0x2E000;
ptr++;
if(ptr >= ((char *)(0x2E600)))
{
ptr = (char *)0x22000;
}
__no_operation();
}
I have already compared the C code with the assembly. The mixed C and assembly code of the 2nd if statement (gives us wrong behaviors) is shown below:
*the code was generated by CCS v4.0.1.01001*
99 ;----------------------------------------------------------------------
100 ; 25 | ptr = (char *)0x2E000;
101 ;----------------------------------------------------------------------
102 000026 1900 MOVX.A #0x2e000,0(SP) ; [] |25|
000028 40F1
00002a E000
00002c 0000
103 .dwpsn file "../main.c",line 26,column 2,is_stmt
104 ;----------------------------------------------------------------------
105 ; 26 | ptr++;
106 ;----------------------------------------------------------------------
107 00002e 1800 ADDX.A #1,0(SP) ; [] |26|
000030 53D1
000032 0000
108 .dwpsn file "../main.c",line 27,column 2,is_stmt
109 ;----------------------------------------------------------------------
110 ; 27 | if(ptr >= ((char *)(0x2E600)))
111 ;----------------------------------------------------------------------
112 000034 1900 CMPX.A #0x2e600,0(SP) ; [] |27|
000036 90F1
000038 E600
00003a 0000
113 00003c 2804 JLO $C$L2 ; [] |27|
114 ; [] |27|
I found that the CMPX.A instruction doesn't behave correctly. It shouldn't set the carry bit because of the negative compare result.
However, the carry bit was set when I run the code line by line. I don't know why because the code works perfectly when large data memory model is disabled.
After this, I use IAR to run the same code, it works well. So, I compared the assembly generated by IAR and CCSv4. An interesting thing is that IAR doesn't use the extended command CMPX.A to compare two values.
They just use some normal commands to do the same thing like CMPX.A does. However, to use normal commands to do CPMX.A ' s job will introduce at least 7 lines of assembly instead of 2 (a compare and a jump) .
So, it looks like there is something wrong with TI's extended instructions when large data memory model is enabled, and I have no idea about how to fix this problem.
The CPU and tools that I used for my test are described below:
* CPU: MSP430F5436
* Software: CCSv4 (Version:4.0.1.01001)
* Code generation tool version: 3.2.1
* Runtime support library: rts430xl.lib
* Data memory model: Large data memory model
* FET: TI's MSP-FETU430IF
* EV board: MSP-TS430PZ5x100
I have reported this problem to TI's support team. However, they can't work it out, and suggest me to look for some help from here.
So, any help or suggestions will be great because I stuck on this problem for a while. I really want to solve this problem as soon as possible.
Thanks
Regards
Liu