打印

KEIL中函数定位的问题,急

[复制链接]
4297|13
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
linghua1100|  楼主 | 2010-10-22 20:44 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
沙发
原野之狼| | 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}; //对这个数组进行绝对定位

使用特权

评论回复
5
batsong| | 2010-10-22 21:43 | 只看该作者
楼上的方法还是给指针赋值啊,并没有改变函数的存储位置啊

去找找lx51.exe的说明,链接器应该有相关功能

使用特权

评论回复
6
一级菜鸟| | 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)

使用特权

评论回复
7
一级菜鸟| | 2010-10-22 21:59 | 只看该作者
二姨家贴HTML不行,贴图算了

使用特权

评论回复
8
一级菜鸟| | 2010-10-22 22:12 | 只看该作者
定位多个函数,格式间加逗号就行,但是要注意地址从左到右必须是从小到大

使用特权

评论回复
9
免证入网| | 2010-10-22 22:44 | 只看该作者
用_at_,如char code xx  _at_  0x003b;以后的都在0x003b以后存储

使用特权

评论回复
10
xiaoding18| | 2010-10-22 22:57 | 只看该作者
这个还真没试过,貌似在微机原理中用汇编可以实现,但忘记了。

使用特权

评论回复
11
xwj| | 2010-10-22 23:01 | 只看该作者
上次折腾半天没搞定,最后还是单独开了个文件,绝对定位

使用特权

评论回复
12
mohanwei| | 2010-10-22 23:14 | 只看该作者
单独开一个文件的确是最轻松的

使用特权

评论回复
13
20061002838| | 2010-10-23 09:05 | 只看该作者
STC单片机Keil中C语言函数定位的方法.rar (215.84 KB)
用这个方法,我试过,可以的
像你说的,一个放在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

使用特权

评论回复
14
chenxu_1| | 2010-10-23 09:10 | 只看该作者
为什么要定位啊?有什么好处?

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

0

主题

12

帖子

1

粉丝