ARM Technical Support Knowledge Articles

ARRAY INDEX ARITHMETIC

Applies to: CX51 C Compiler

Answer


Information in this article applies to:


QUESTION

The CX51 Compiler does not allow the definition of objects that are bigger then 64KB. Is there a way to define big objects in assembler and use pointer arithmetic in the CX51 Compiler?

ANSWER

Yes. CX51 Version 7.11 implements long pointer arithmetic and allows index calculations across the 64KB segment limits. You may define objects in assembly language (using HDATA or HCONST segments).

With (unsigned) long variables (or cast to long) the compiler generates address arithmetic that allows you to access huge arrays. You just need to assign the start address of the array to a far pointer.

Example:

unsigned char far *cp;        // allows to access any memory location

struct s  {                        // example with a struct
  unsigned int  a[10];
  unsigned char c;
};

struct s far *sp;                  // may be anywhere in memory

unsigned long l1, l2;
unsigned char c;
unsigned int  i;

void main (void)  {
  c = cp[l1 + 0x34000L];           // address calculation
  cp[l1 + l2] = c;
  i = sp[l1].a[(unsigned long)c];  // using long cast operations,
                                   // even arrays inside a struct may
                                   // cross 64KB segment boundaries.
}

MORE INFORMATION

SEE ALSO

Article last edited on: 2005-10-06 12:36:41

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