Keil Logo

CX51: ARRAY INDEX ARITHMETIC


Information in this article applies to:

  • CX51 Version 7.10

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

FORUM THREADS

The following Discussion Forum threads may provide information related to this topic.

Last Reviewed: Thursday, October 6, 2005


Did this article provide the answer you needed?
 
Yes
No
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.