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

do it have andy option for use "inc dptr" to optimize the pointer that pointer to xdata

For keil c51, do it have andy option for use "inc dptr" to optimize the pointer that pointer to xdata.

we can see the following c program, I use one pointer "dbuf", and the following value that assigned to this memory is sequential

we can see the disassembly code that generated by keil.
if it use "inc dptr", then can reduce code size and code speed.

void test_inc_dptr(char buf_select) small
{
        unsigned char xdata * data dbuf;

        dbuf = 0;
        if(buf_select)
                dbuf = 0x200;

        dbuf[0] = 0x55;
        dbuf[1] = 0x53;
        dbuf[2] = 0x42;
        dbuf[3] = 0x53;
}
// after keil compile, the assemble code is the following.
; void test_inc_dptr(char buf_select)

        RSEG  ?PR?_test_inc_dptr?SCSI
_test_inc_dptr:
        USING   0
                        ; SOURCE LINE # 1351
;---- Variable 'buf_select?3165' assigned to Register 'R7' ----
; {
                        ; SOURCE LINE # 1352
;       unsigned char xdata * data dbuf;
;
;       dbuf = 0;
                        ; SOURCE LINE # 1355
;---- Variable 'dbuf?3166' assigned to Register 'R4/R5' ----
        CLR     A
        MOV     R5,A
        MOV     R4,A
;       if(buf_select)
                        ; SOURCE LINE # 1356
        MOV     A,R7
        JZ      ?C0313
;               dbuf = 0x200;
                        ; SOURCE LINE # 1357
        MOV     R4,#02H
?C0313:
;
;       dbuf[0] = 0x55;
                        ; SOURCE LINE # 1359
        MOV     DPL,R5
        MOV     DPH,R4
        MOV     A,#055H
        MOVX    @DPTR,A
;       dbuf[1] = 0x53;
                        ; SOURCE LINE # 1360
        INC     DPTR
        MOV     A,#053H
        MOVX    @DPTR,A
;       dbuf[2] = 0x42;
                        ; SOURCE LINE # 1361
        MOV     DPL,R5                                  // does this line can optimize to omit?
        MOV     DPH,R4                                  // does this line can optimize to omit?
        INC     DPTR                                    // does this line can optimize to omit?
        INC     DPTR
        MOV     A,#042H
        MOVX    @DPTR,A
;       dbuf[3] = 0x53;
                        ; SOURCE LINE # 1362
        MOV     DPL,R5                                  // does this line can optimize to omit?
        MOV     DPH,R4                                  // does this line can optimize to omit?
        INC     DPTR                                    // does this line can optimize to omit?
        INC     DPTR                                    // does this line can optimize to omit?
        INC     DPTR
        MOV     A,#053H
        MOVX    @DPTR,A
; }
                        ; SOURCE LINE # 1363
        RET
; END OF _test_inc_dptr

0