Keil Logo

Linker Location Controls

Another method of referencing explicit memory locations is to declare the variables in a stand-alone C module and use the linker location directives to locate them at an absolute memory address.

In the following example, the alarm_control structure is defined containing the variables to locate.

struct alarm_st  {
  unsigned int alarm_number;
  unsigned char enable flag;
  unsigned int time_delay;
  unsigned char status;

xdata struct alarm_st alarm_control;

The C51 Compiler generates an object file for the above source (ALMCTRL.C) and includes a segment for variables in the xdata memory area. Since alarm_control is the only variable declared in this module, it is the only variable in the xdata segment. The name of the segment is ?XD?ALMCTRL.

The linker can locate a segment at any address. The following examples show how to locate the ?XD?ALMCTRL segment starting at offset 0x2000 in the xdata memory area.

For the BL51 Linker...

BL51 ... almctrl.obj XDATA(?XD?ALMCTRL(2000h)) ...

For the LX51 Linker...

LX51 ... almctrl.obj SEGMENTS(?XD?ALMCTRL(X:0x2000)) ...

You may also locate segments in the other memory areas like code, xdata, pdata, idata, and data. Refer to the BL51 Linker User's Guide or the LX51 Linker User's Guide for more information.

Related Knowledgebase Articles

  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.