Chinaunix首页 | 论坛 | 博客
  • 博客访问: 444286
  • 博文数量: 72
  • 博客积分: 3186
  • 博客等级: 中校
  • 技术积分: 1039
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-07 16:53
文章分类

全部博文(72)

文章存档

2012年(1)

2011年(5)

2010年(10)

2009年(56)

我的朋友

分类: 嵌入式

2009-09-18 16:35:24

--------------------------------------------------------------------------------------------------------------------------------------




31        28 27  25  24 23                                            0
 +----------+------+---+----------------------------------------------+
 |   Cond   | 101  | L |                    Offset                    |
 +----------+------+---+----------------------------------------------+

  Branch instructions contain a signed 2's complement 24 bit offset. This is shifted left two bits, sign extended to 32 bits, and added to the PC. The instruction can therefore specify a branch of +/- 32Mbytes. The branch offset must take account of the prefetch operation, which causes the PC to be 2 words (8 bytes) ahead of the current instruction.
  Branches beyond +/- 32Mbytes must use an offset or absolute destination which has been previously loaded into a register. In this case the PC should be manually saved in R14 if a Branch with Link type operation is required.

上图里已经表示得很明白,我们来看一下低24[23:0]

[23:0]是带符号的24位二进制数补码,表示偏移量,用它来计算地址。计算地址分三个步骤:

  1. 左移两位(低两位为0,为了地址以“字”对齐)

  2. 带符号扩展为32

  3. 加上当前pc

因此可以在+/-32M的地址范围内跳转。

对于其地址的计算过程,以及移位等,我们不必去了解太深,因为这部分的工作汇编器已经帮我们做了。在这里我们需要了解的是:b/bl跳转的地址是与当前pc有关的,它的跳转是相对跳转(相对于当前地址);跳转的范围为+/-32M


可以写几句代码来具体分析下:

.global _start
.align 0
_start:
        b loop1
loop1:
        b loop2
loop2:
        b .
        .end



汇编编译过后,再反汇编,得到:

Disassembly of section .data:

00000000 <.data>:
   0: eaffffff b 0x4
   4: eaffffff b 0x8
   8: eafffffe b 0x8


1. 低24位 ffffff
2. 左移两位并扩展 ffff fffc
3. 加上当前pc 8
4. 最后得到 0x4

切记最后的跳转到 0x4 是通过当前pc记算得来的。


-------------------------------------------------------------------------------------------------------------------------------------------
参考资料: 《2410 USER‘S MANUAL》 第三章
          《2410 完全开发流程》







阅读(3238) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~