Keil Logo


Information in this article applies to:

  • C51 Version 5.50


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.


The following will work:

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

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

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

Code generated for the increment:

0000 0500    R     INC     asdf+01H


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

Last Reviewed: Wednesday, February 21, 2007

Did this article provide the answer you needed?
Not Sure
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.