Keil Logo

C51: Reserving Code Space

QUESTION

How do I reserve code space so the compiler and linker will automatically split my program between code space from 0x0000 to 0x1FFF and 0x8000 to 0xFFFF?

ANSWER

There are a number of ways you can use the C51 compiler and linker to avoid using sections of the CODE space. The easiest way is to declare an array in CODE that resides at the desired address. For example, to exclude the CODE space from 0x2000 to 0x7FFF, the following code will work.

unsigned char code dummy [0x6000] _at_ 0x2000;
xdata unsigned char *dummy2 = &dummy;  // To avoid Warnings

Note that the array "dummy" is 6000 characters (bytes) long and starts at 0x2000 in the CODE space. The XDATA pointer, "dummy2", is used to avoid compiler and linker warnings. If you omit it, the linker will probably complain that nothing uses the dummy array.

MORE INFORMATION


Last Reviewed: Thursday, February 25, 2021


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.