ARM Technical Support Knowledge Articles

ELIMINATING 16-BIT POINTER INCREMENTS

Applies to: C51 C Compiler

Answer


Information in this article applies to:


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

Article last edited on: 2007-02-21 12:57:46

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential