| |||||
Technical Support Support Resources
Product Information | CX51: ARRAY INDEX ARITHMETICInformation in this article applies to:
QUESTIONThe 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? ANSWERYes. 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 ALSOFORUM THREADSThe following Discussion Forum threads may provide information related to this topic.
Last Reviewed: Thursday, October 06, 2005 | ||||
| |||||