We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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
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!