KeilC如何通过linker将文件放入指定存储地址

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.

 

reference: http://www.keil.com/support/man/docs/c51/c51_ap_linkerloc.htm

你可能感兴趣的:(KeilC如何通过linker将文件放入指定存储地址)