I have a debugging problem that is utterly baffling to me. I need some clues on how to proceed. I'm using CCSv4 with the LogicPD EVM c6748 board.
Something is contaminating memory, but it occurs in a repeatable fashion, always at the same point in the code -- yet the code itself has no visible fault! The code looks fine.
Here is a snippet of the code where the problem occurs:
int i;
unsigned short a[6043], b[6043];
for ( i=0; i<6043; i++) a[i] = b[i];
The error occurs when i=5110. Yet there's nothing wrong with the code.
Moreover, the error is that i (the index) SUDDENLY JUMPS TO A LARGE VALUE. The index i is a local variable that the compiler has stored on the stack, and I can visibly watch this stack location as I step through the disassembled code. The index i is incremented nicely until it gets to 5110, whereupon it inexplicably jumps to a large value.
Here is the same code as seen from the disassembler (with my added comments). I marked in red where the index i gets contaminated on the stack. Again, the code looks fine, yet the error occurs. I need some ideas on how to proceed with debugging:
ZERO.L2 B4 // B4 = 0 = i
STW.D2T2 B4,*+SP[1] // SP[1] = 0 = i
NOP 2 //
MVK.S2 0x179b,B5 // B5 = 6043
CMPLT.L2 B4,B5,B0 // Is B4 < B5, result in B0
[!B0] B.S1 C$DW$L$_memoryroutine$28$E (PC+88 = 0xc0a59118)
NOP 5
MVK.S2 0x2600,B6 // B6 = &b
MVKH.S2 0xc07c0000,B6 // "
MV.L2 B4,B5 // B5 = B4 = i
|| LDHU.D2T2 *+B6[B4],B4 // B4 = b[i]
MVK.S2 0xffffe060,B9 // B9 = &a
MVKH.S2 0x80000000,B9 // "
NOP 2 // "
STH.D2T2 B4,*+B9[B5] // a[i] = B4 [index i gets clobbered here on the stack]
NOP 2 //
LDW.D2T2 *+SP[1],B4 // B4 = i
NOP 4 //
ADD.L2 1,B4,B4 // i++
STW.D2T2 B4,*+SP[1] // SP[1] = i
NOP 2 //
MVK.S1 0x179b,A3 // A3 = 6043
CMPGT.L1X A3,B4,A1 // Is 6043 > i? Result in A1
[ A1] B.S1 C$L42 (PC-48 = 0xc0a590d0) // Branch back if greater than
NOP 5