Keil™, An ARM® Company

Technical Support

C51: ELIMINATING 16-BIT POINTER INCREMENTS


Information in this article applies to:

  • C51 Version 5.50

QUESTION

I am using a pointer to address some custom hardware. The hardware is mapped into XDATA memory and is page aligned.

When I increment the pointer, it does a 16-bit increment. Since my hardware is page aligned, I know there is no need to load the upper 8 bits and increment them.

Here is the code produced:

00D0 0500    R     INC     linePtr+01H
00D2 E500    R     MOV     A,linePtr+01H
00D4 7002            JNZ     ?C0021
00D6 0500    R     INC     linePtr

Is there anything I can do in C to force this to only do an 8-bit increment? I prefer to stay in the C language. This would save me lots of code space because, as is, every increment takes 8 bytes of code and only the first 2 bytes are required.

I cannot declare the pointer as pdata.

ANSWER

The following will work:

union ptr_union
  {
  unsigned char xdata *ptr;
  unsigned char dummy[2];
  }
asdf;

#define INC_PTR(x)   ((x).dummy[1]++)
#define USE_PTR(x)   ((x).ptr)

void main(void) {
  INC_PTR(asdf);
  USE_PTR(asdf)[0] = 5;
}

Code generated for the increment:

0000 0500    R     INC     asdf+01H

MORE INFORMATION

  • Refer to Pointers in the Cx51 User's Guide.

Last Reviewed: Wednesday, February 21, 2007


Did this article provide the answer you needed?
 
Yes
No
Not Sure