This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Is it a compiler bug??

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

Parents
  • 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]);
    

    You could probably clean up the code a lot with the proper declarations to avoid all that intermediate casting. We can't see the declaration for BankH1, but the offset of OffsetData could be folded into the hard-wired address 0, and then you could just add index to the base (or use the array reference syntax). Or perhaps just declare a BankH1 _at_ 0.

Reply
  • 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]);
    

    You could probably clean up the code a lot with the proper declarations to avoid all that intermediate casting. We can't see the declaration for BankH1, but the offset of OffsetData could be folded into the hard-wired address 0, and then you could just add index to the base (or use the array reference syntax). Or perhaps just declare a BankH1 _at_ 0.

Children
No data