This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MCU routine escapes when UINT_MAX is called...



Hello all,

I have an interesting issue here with CCS 4.2.4...

I included <limits.h> in my file and am trying to use UINT_MAX for some bounds checking, but whenever UINT_MAX is called the routine exits early. 

Here is my code snippet:

if (segCount == 0) //Write the value

{

switch(DebugVars[writeAddress].VarData.VarSize) //

{

case 1:

if (payload<=(Uint64)UINT_MAX)

....

}

}

Right there at that last conditional statement in red, the program immediately exits, this happens both when I step through the code and during free run, but it does not happen when I Assembly Step. I will list the assembly at the end. 

I have even reduced the code to:

tmp=UINT_MAX;

at the same position in my algorithm and it still fails.  However, if I move tmp=UINT_MAX to the beginning of the function, it works as expected.

Any ideas?

0x3E9306:   2901        CLRC         SXM

0x3E9307:   060E        MOVL         ACC, @0xe

0x3E9308:   FF47        SFR          ACC, 8

0x3E9309:   D400        MOVB         XAR4, #0x0

0x3E930A:   9100        ANDB         AH, #0x0

0x3E930B:   FF5A        MOVL         P, ACC

0x3E930C:   CC0F0300    AND          AL, @0xf, #0x300

0x3E930E:   FFC7        LSR          AL, 8

0x3E930F:   FF83        LSL          AL, 4

0x3E9310:   2DA9        MOV          T, @AL

0x3E9311:   A8A9        MOVL         @ACC, XAR4

0x3E9312:   5652        LSL64        ACC:P, T

0x3E9313:   A944        MOVL         *-SP[4], P

0x3E9314:   A318        MOVL         P, @0x18

0x3E9315:   8AA9        MOVL         XAR4, @ACC

0x3E9316:   A842        MOVL         *-SP[2], XAR4

0x3E9317:   061A        MOVL         ACC, @0x1a

0x3E9318:   00FEA7C7    FFC          XAR7, LL$$OR

0x3E931A:   A918        MOVL         @0x18, P

0x3E931B:   1E1A        MOVL         @0x1a, ACC

0x3E931C:   2BAA        MOV          @PH, #0

0x3E931D:   28ABFFFF    MOV          @PL, #0xffff

0x3E931F:   9A00        MOVB         AL, #0x0

0x3E9320:   A914        MOVL         @0x14, P

0x3E9321:   9B00        MOVB         AH, #0x0

0x3E9322:   1E16        MOVL         @0x16, ACC

0x3E9323:   9201        MOV          AL, @0x1

0x3E9324:   56C00081    BF           C$L50, NEQ

0x3E9326:   6F52        SB           C$L43, UNC

  • Wow, I got it... a freaking space!  The limits.h file defines UINT_MAX as follows

    UINT_MAX= 65535u

     

    No good: if (payload<=(Uint64)UINT_MAX)

    Good: if (payload<=(Uint64) UINT_MAX )

    Lots of wasted time on this one!