Quantcast
Channel: Forums - Recent Threads
Viewing all articles
Browse latest Browse all 262198

Compiler/TMS320F28335: int -> long cast issue with negative numbers

$
0
0

Part Number:TMS320F28335

Tool/software: TI C/C++ Compiler

I observed a strange behavior in my program which I was able to trace to a int to long cast that doesn't behave as expected with a negative int. 

The code is simply:

typedef         int                             INT16S;
typedef         long                            INT32S;

INT16S var1;
INT32S var2;
.
.
. var2 = (INT32S) var1;

However, when the int variable is negative, somehow the compiler fails to cast it properly to long. 

The disassembly looks like:

761F0338    MOVW         DP, #0x338
8517        MOV          ACC, @0x17
761F02CD    MOVW         DP, #0x2cd
1E28        MOVL         @0x28, ACC

And checking the memory shows that the high word is all zeros whereas I would expect it to be padded with F's. Conversely if I explicitly write

var2 = (INT32S)((INT16S)var1);

The disassembly includes an extra line "SETC SXM" instruction:

3B01        SETC         SXM
761F0338    MOVW         DP, #0x338
8517        MOV          ACC, @0x17
761F02CD    MOVW         DP, #0x2cd
1E28        MOVL         @0x28, ACC

And the result of the cast is padded with F's in the upper word. 

Is this the expected behavior?

I am not sure whether this could be related to using the JTAG debugging probe.

Also, I am compiling with the -O3 flag so maybe this could be due to an optimization?  

I would be very grateful for any hint on this issue.

Best regards,

Laurent Badel


Viewing all articles
Browse latest Browse all 262198

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>