unsigned int Begin; ... Begin=*(U16 CODE *)Begin; ... ;---- Variable 'Begin' assigned to Register 'DPTR' ---- 002C 8F82 MOV DPL,R7 002E F583 MOV DPH,A ; SOURCE LINE # 82 0030 E4 CLR A 0031 93 MOVC A,@A+DPTR 0032 F583 MOV DPH,A <--- Error: This line change the DPTR value. 0034 7401 MOV A,#01H 0036 93 MOVC A,@A+DPTR <--- Error: Wrong address. 0037 F582 MOV DPL,A
Looks like a code generator bug to me. "Begin" lives in the DPTR; it takes two MOVCs to fetch a new value; and the first MOVC goes (almost) straight into the DPTR, altering it before the MOVC of the second byte. The address used for the second MOVC is not the same as the address used for the first MOVC. It may be that the optimizer thinks it's okay to trash the value of Begin because it will no longer be used. That would explain why uncommented the later statement fixes the problem. The compiler would preserve the value of Begin for the later use. You don't need to assign Begin back to itself anyway; it's just a temporary. How about just:
pbSrc = (U8 CODE *) *(U16 CODE *)(&((BankH1 CODE *)0)->OffsetData[Index]);