ARM Technical Support Knowledge Articles

CONSTANT ARRAYS LARGER THAN 64KB

Applies to: C51 C Compiler

Answer


Information in this article applies to:


QUESTION

I want to create a constant array larger than 64KB using the following construct:

#pragma ROM(D512K)

unsigned char const far array[] = {
 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,
  :
}

Since the data is more than 64KB, I receive the error message:

*** ERROR C249: 'array': ALLOCATION EXCEEDS 64K

Is there a way to create a constant array larger than 64KB?

ANSWER

Yes. You may use an assembly program to define such an large array. Your example would translate into:

PUBLIC array

?HC?ARRAY SEGMENT HCONST
RSEG ?HC?ARRAY
array:
DB  1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16
  :

END

The AX51 assembler has no limitations on the size of an array.

In C51 you may address this array as shown below:

#pragma ROM(D512K)

extern unsigned char const far array[];

unsigned char test (long l)  {
  unsigned char c;

  c = array[l];
  return c;
}

Note that the array index l is defined as unsigned long to allow 24-bit address arithmetic.

MORE INFORMATION

SEE ALSO

Article last edited on: 2005-10-10 11:08:32

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