Linker Location Controls

The second method of referencing explicit memory location is to declare the variables in a stand-alone C module and use the location control directives of the L51 Linker/Locator to specify an absolute memory address.

In the following example, assume that we have a structure called alarm_control  that we want to reside at address 2000h in xdata. We start by entering a source file named ALMCTRL.C  that contains only the declaration for this structure.
.
.
.
struct alarm_st
{
unsigned int alarm_number;
unsigned char enable flag;
unsigned int time_delay;
unsigned char status;
unsigned int high_level;
unsigned int low_level;
};

xdata struct alarm_st alarm_control;
.
.
.

The C51 compiler generates an object file for ALMCTRL.C  and includes a segment for variables in the xdata memory area. Because it is the only variable declared in this module, alarm_control  will be the only variable in that segment. The name of the segment will be ?XD?ALMCTRL.

The L51 Linker/Locator allows you to specify the base address of any segment by using the location control directives. Because the alarm_control  variable was declared to reside in xdata, the XDATA L51 directive must be used as follows:
XDATA(?XD?ALMCTRL(2000h)) …

This instructs the linker to locate the segment named ?XD?ALMCTRL at address 2000h in the xdata memory area.

There are linker directives for locating segments in the code, xdata, pdata, idata, and data memory areas. Refer to the L51 Linker/Locator for more information.