How to locate a subroutine segment at a fixed address?

Publisher:SparkStar22Latest update time:2015-03-10 Source: laogu Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
1. Function location:
If you want to put the function
int BIN2HEX(int xx)
{
  ...
}
in the C source file tools.c at 0x1000 in CODE MEMORY, compile the project first, then open the M51 file of the project, and find the name of the function to be located under the line
* * * CODE MEMORY * * * , which should be in the form of: CODE xxxxH xxxxH UNIT ?PR?_BCD2HEX?TOOLS Then fill in the following content in: Project->Options for Target ...->BL51 Locate: Code : ?PR?_BCD2HEX?TOOLS(0x1000) Build again, and you will find that the function has been placed at 0x1000 in CODE MEMORY in M51. 2. Variable location with initial value: To locate a variable at an absolute position and assign an initial value, use _at_ If it cannot be completed, do the following: Create a new file in the project, such as InitVars.c, and assign an initial value to the variable to be processed (assuming it is a code variable ): char code myVer = {"COPYRIGHT 2001-11"}; Then add the file to the project, compile, open the M51 file, if the definition is code type, you can find it under * * * CODE MEMORY * * * : CODE xxxxH xxxxH UNIT ?CO?INITVARS Then fill in: Project->Options for Target ...->BL51 Locate: Code : ?CO?INITVARS(0x200) and compile again. Correspondingly, if it is an xdata variable, write in InitVars.c: char xdata myVer = {"COPYRIGHT 2001-11"}; then add the file to the project, compile, open the M51 file, and under * * * XDATA MEMORY * * * you can find: XDATA xxxxH xxxxH UNIT ?XD?INITVARS Then fill in: ?XD?INITVARS(0x200) in: Project->Options for Target ...->BL51 Locate: Xdata and compile again. Correspondingly, if the variables defined are data/idata, then handle them accordingly. 3. If there are multiple variables or functions to be located at absolute addresses, they should be arranged in order from low to high addresses.



































Reference address:How to locate a subroutine segment at a fixed address?

Previous article:ds1868c driver
Next article:Parallel I/O Port Programming Example

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号