DPTR constantly reloaded

I have some code to transfer a large amount of data over a SPI port running at the system clock/2 so I need my code to be as fast as possible. The code generated for my current method does not seem to be as optimal as it could be. I am using optimization (8, speed) with the 7.07 C51. Here is a simplified version of my code:

//this variable set in buffer data function
static unsigned char xdata * data spiDataPtr;

void transferData(void) small {
     //do not want to store changes in
     //spiDataPtr so use temp pointer
     unsigned char xdata * tempPtr;
     unsigned char data i;
     unsigned char data temp;

     tempPtr = spiDataPtr;

     //transfer set block size
     for(i = 0xff; i != 0; i--) {
          SPIDATA = *tempPtr; //initiate transfer
          tempPtr++; //prepare for next send while busy transfering
          while(!SPITXDONE); //wait for transfer to complete
          temp = SPIDATA; //read to avoid colission error
     }
}

The compiler increments tempPtr in its data location and then reloads it into the DPTR each time tempPtr is increased. I do not need the final value of tempPtr. What I would like is for the DPTR to be loaded when tempPtr is initially set and then for the DPTR to be increased by INC DPTR. I figure this would be quicker even if the value of tempPtr was needed because the DPTR could be moved back into tempPtr at the end of the loop. Is there a way to get the compiler to do this short of assembly?

Parents
  • Here's what I get when I compile with C51 V7.07. Note that I just made up address values for the SPI SFRs.

                 ; FUNCTION transferData (BEGIN)
                                               ; SOURCE LINE # 6
                                               ; SOURCE LINE # 13
    ;---- Variable 'tempPtr' assigned to Register 'DPTR' ----
    0000 850082      R     MOV     DPL,spiDataPtr+01H
    0003 850083      R     MOV     DPH,spiDataPtr
                                               ; SOURCE LINE # 16
    ;---- Variable 'i' assigned to Register 'R7' ----
    0006 7FFF              MOV     R7,#0FFH
    0008         ?C0001:
                                               ; SOURCE LINE # 17
    0008 E0                MOVX    A,@DPTR
    0009 F590              MOV     SPIDATA,A
                                               ; SOURCE LINE # 18
    000B A3                INC     DPTR
    000C         ?C0004:
                                               ; SOURCE LINE # 19
    000C 3091FD            JNB     SPITXDONE,?C0004
    000F         ?C0005:
                                               ; SOURCE LINE # 20
    000F 859000      R     MOV     temp,SPIDATA
                                               ; SOURCE LINE # 21
    0012 DFF4              DJNZ    R7,?C0001
                                               ; SOURCE LINE # 22
    0014         ?C0006:
    0014 22                RET
                 ; FUNCTION transferData (END)
    

    This sounds like what you are looking for. I used optimizer level 8, speed. Maybe there is something else you are doing?

    Jon

Reply
  • Here's what I get when I compile with C51 V7.07. Note that I just made up address values for the SPI SFRs.

                 ; FUNCTION transferData (BEGIN)
                                               ; SOURCE LINE # 6
                                               ; SOURCE LINE # 13
    ;---- Variable 'tempPtr' assigned to Register 'DPTR' ----
    0000 850082      R     MOV     DPL,spiDataPtr+01H
    0003 850083      R     MOV     DPH,spiDataPtr
                                               ; SOURCE LINE # 16
    ;---- Variable 'i' assigned to Register 'R7' ----
    0006 7FFF              MOV     R7,#0FFH
    0008         ?C0001:
                                               ; SOURCE LINE # 17
    0008 E0                MOVX    A,@DPTR
    0009 F590              MOV     SPIDATA,A
                                               ; SOURCE LINE # 18
    000B A3                INC     DPTR
    000C         ?C0004:
                                               ; SOURCE LINE # 19
    000C 3091FD            JNB     SPITXDONE,?C0004
    000F         ?C0005:
                                               ; SOURCE LINE # 20
    000F 859000      R     MOV     temp,SPIDATA
                                               ; SOURCE LINE # 21
    0012 DFF4              DJNZ    R7,?C0001
                                               ; SOURCE LINE # 22
    0014         ?C0006:
    0014 22                RET
                 ; FUNCTION transferData (END)
    

    This sounds like what you are looking for. I used optimizer level 8, speed. Maybe there is something else you are doing?

    Jon

Children
More questions in this forum