原创 [转] understand "add r0, pc, #-(8+.-StackData)"

2011-3-18 11:13 1306 4 4 分类: MCU/ 嵌入式
Subject: Re: How to understand "add r0, pc, #-(8+.-StackData)"
Robin Steven <armrobin@xxxxxxxxx> wrote:
> I don't understand the instruction:
> add r0, pc,#-(8+.-StackData)
> in my known, the "." symbol is current address,
> and "pc-8" is current address.
> thus
> "add r0, pc, #-(8+.-StackData)" is equal "add r0, r0, StackData" ???

The above instruction would be equivalent to "mov r0, #StackData".

There are 2 problems with using a mov instruction - (1) it is possible
that the StackData value could not be encoded in the 12 bits of the
shifter operand of the "mov" instruction (could use "ldr" instead) and
(2) it is not position independent (in case you use XIP for
example). The (8+.-StackData) value will be evaluated at the compile
time and it represents an offset from the current position, thus
allowing the loading at a different address and still preserving the
relative position.
http://www.hzlitai.com.cn/bbs/viewthread.php?tid=5042
看了各种书上和ARM公司的PDF文件里给出的解释是“是当前指令的地址”
我对“.”的理解多了一条:它和编译连接地址有关。
例:
add r0, pc,#-(8+.-StackData) ; @ where to read values (relative)
在这里,“."表示的是当前指令的地址,它应该和编译器里面的连接设置有关;StackData是个标号,也和连接设置有关。
而这指令中的PC的内容是当前指令的地址加8,它和连接设置无关,只和这条指令执行时的地址有关。
综上所述,此条指令完成的功能是把到StackData的偏移量加上PC值,送到RO里。
PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
我要评论
0
4
关闭 站长推荐上一条 /4 下一条