Keil Logo

BL51: INITIALIZING & LOCATING A VARIABLE TO A FIXED ADDRESS


Information in this article applies to:

  • C51 All Versions

QUESTION

Can I direct my initialized constant string to a specific location? I tried using the _at_ keyword in C51, but I can't initialize this variable and locate it at a fixed address.

ANSWER

Yes. To initialize and locate a constant string, place the string in a file by itself. Then, use the linker to locate it at the address you want.

For example: create the following file called TAB1.C:

unsigned char code tab1 [] = { 1, 2, 3, 4, 5, 0 };

When you compile this file, the compiler creates a segment named ?CO?TAB1. This indicates that the data is stored in the code area and the source file is named TAB1.

On the linker command line, specify

BL51 ... CODE(?CO?TAB1(08000h)) ...

to locate this array at address 8000h.

In µVision...

  • Open the Options Menu
  • Select Linker Options
  • Choose the Segments Tab
  • On the CODE input line, enter ?CO?TAB1(08000h)

This also locates the table at 8000h.

Refer to the 8051 Utilities User's Guide for more information.

Note that this will work for variables located in XDATA, DATA, and IDATA as well as those located in the CODE area.

MORE INFORMATION

SEE ALSO

FORUM THREADS

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

Last Reviewed: Tuesday, March 27, 2007


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.