KEIL中函数定位的问题,急

[复制链接]
 楼主| linghua1100 发表于 2010-10-22 20:44 | 显示全部楼层 |阅读模式
请教在KEIL中定位两个及以上函数的方法。比如我要使函数FUNC1放在CODE区0X2000,FUNC2放在CODE区0X5000,请问怎么办?
我只知道一个函数的定位,用CODE(?PR?FUNC1?FILENAME?(0X2000)),但增加一个时就报错,只能FUNC2紧接着FUN1,不能间隔,弄了很久,不知道怎么办,请各位大侠帮帮忙。
原野之狼 发表于 2010-10-22 20:51 | 显示全部楼层
绝对地址定位函数指针变量数组
 楼主| linghua1100 发表于 2010-10-22 20:57 | 显示全部楼层
不太明白,能不能说的明白点?大侠
我所理解的是用函数指针是否只能指向、调用绝对地址的函数,不能给一个特定的函数定位吧?
不知理解有错没?
原野之狼 发表于 2010-10-22 21:08 | 显示全部楼层
typedef void(*PFN)(void);

void foo1(void);
void foo2(void);

PFN pfoo[2] = {foo1,foo2}; //对这个数组进行绝对定位
batsong 发表于 2010-10-22 21:43 | 显示全部楼层
楼上的方法还是给指针赋值啊,并没有改变函数的存储位置啊

去找找lx51.exe的说明,链接器应该有相关功能
一级菜鸟 发表于 2010-10-22 21:56 | 显示全部楼层
链接时决定的,要这么整:



描述下语法
?PR?SYSTEMINIT?MAIN (0x800)

SYSTEMINIT是个函数
它包含在MAIN.c编译出的main.obj内,绝对定位地址为0x800

Keil的帮助里是这么写的:
CODE Linker Directive
AbbreviationCO
ArgumentsCODE (〚range〛 〚segment 〚(address)〛 〚, ...〛〛)
DefaultNone.
µVisionOptions — BL51 Locate — Code Range.
Options — BL51 Locate — Code Segments.
DescriptionThe CODE directive specifies:
  • The address range for relocatable CODE segments.
  • The order of relocatable CODE segments in memory.
  • The absolute memory location of individual CODE segments.
This directive is specified as follows:
CODE (〚range, ...〛 〚segment 〚(address)〛 〚, ...〛〛)Where
rangespecifies the address range(s) to use for CODE segments.
segmentis the name of a segment.
addressis a physical address at which the segment is to be located.
Note
  • The BL51 Linker allows you to use wildcards when locating program segments. For example, ?PR?*?MYFILE may be used to represent all program segments from the MYFILE source file.
See AlsoBIT, DATA, IDATA, PDATA, PRECEDE, RAMSIZE, STACK, XDATA
ExampleThe example below specifies that relocatable CODE segments be located in the address space 0 – 0x3FFF and 0x8000 – 0xFFFF:
BL51 MYPROG.OBJ CODE(0 - 0x3FFF, 0x8000 - 0xFFFF)To specify the order for segments, you must include the names of the segments separated by commas. The following example will place the ?PR?FUNC1?A and ?PR?FUNC2?A segments at the beginning of the CODE memory:
BL51 A.OBJ CODE(?PR?FUNC1?A, ?PR?FUNC2?A)You can also specify the memory location for a segment. The example below will place the ?PR?FUNC1?A segment at 800h and the ?PR?FUNC2?A segment after at this segment:
BL51 A.OBJ CODE(?PR?FUNC1?A (0x800), ?PR?FUNC2?A)

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
一级菜鸟 发表于 2010-10-22 21:59 | 显示全部楼层
二姨家贴HTML不行,贴图算了

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
一级菜鸟 发表于 2010-10-22 22:12 | 显示全部楼层
定位多个函数,格式间加逗号就行,但是要注意地址从左到右必须是从小到大
免证入网 发表于 2010-10-22 22:44 | 显示全部楼层
用_at_,如char code xx  _at_  0x003b;以后的都在0x003b以后存储
xiaoding18 发表于 2010-10-22 22:57 | 显示全部楼层
这个还真没试过,貌似在微机原理中用汇编可以实现,但忘记了。
xwj 发表于 2010-10-22 23:01 | 显示全部楼层
上次折腾半天没搞定,最后还是单独开了个文件,绝对定位
mohanwei 发表于 2010-10-22 23:14 | 显示全部楼层
单独开一个文件的确是最轻松的
20061002838 发表于 2010-10-23 09:05 | 显示全部楼层

用这个方法,我试过,可以的
像你说的,一个放在8000,一个放在5000,要这么写
?PR?_READIAP?DEMO(0x5000), ?PR?_PROGRAMIAP?DEMO(0x8000),?PR?_ERASEIAP?DEMO(0x8016)
即把地址小的放前面,大的放后面,不能乱,下面是我定位的结果
            CODE    5000H     0016H     UNIT         ?PR?_READIAP?DEMO
                    5016H     2FEAH                  *** GAP ***
            CODE    8000H     0016H     UNIT         ?PR?_PROGRAMIAP?DEMO
            CODE    8016H     0014H     UNIT         ?PR?_ERASEIAP?DEMO

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
chenxu_1 发表于 2010-10-23 09:10 | 显示全部楼层
为什么要定位啊?有什么好处?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

0

主题

12

帖子

1

粉丝
快速回复 在线客服 返回列表 返回顶部