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

  • Hello freind,

    when you need to optimize like this you should think about assembler.

    Always yo're freind,

    Zeusti.

    (advisor to Martin Smithers)

  • What optimisation level are you using?

    What other levels have you tried?

    All the available optimisations are listed here: http://www.keil.com/support/man/docs/c51/c51_optimize.htm

    There are no other special "Andy" optimisations!

    There are some options to use a 2nd DPTR on certain derivatives - but they only affect a few library functions. Look up the MOD... options; eg, http://www.keil.com/support/man/docs/c51/c51_modc2.htm

    You may find that the compiler generates more efficient code if you do a structure assignment than individual assignments.

    At the end of the day, as Zeusti says, if it matters this much to you, then you should be writing it in Assembler!

  • .. is according to the standard that any compiler can make any code that makes the variables change correctly without ANY concern for the processing time

    Now most compiler makers take some effort to make the generated code efficient, but they are NOT required to.

    THUS:
    if you have code where the time available vs processor speed becomes critical and the C code does not run fast enough, USE ASSEMBLER.

    I, for one, make projects that are 80-99% C and the rest in assembler.

    A MAJOR PC maker writes BIOS functions in assembler; so, the need for assembler is not restricted to the '51

    Erik