了解ARM汇编分公司偏移量计算 [英] Understanding Arm Assembler Branch Offset Calculation

查看:279
本文介绍了了解ARM汇编分公司偏移量计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白的偏移量为calcualted分支指令(b和在地址0x00011004 BL和0x00011010)与下面列出的拆解code。我想知道,在十六进制code这个问题上的偏移量似乎是0x000001和0x000002。欧普codeS的条件B(EA)和BL(EB)是我所期待的。

感谢每一个提示提前

  MyAssemblerFunc:
00011000 STMDB SP !, {R0 - R3,LR}
00011004 b 00011010
00011008 MOV R0,R0
0001100C MOV R0,R0
00011010 BL | PrintHelloWorld(11020h)|
00011014 LDMIA SP !, {R0 - R3,LR}

相关六角code

  0x00011000 0F 40二维E9 @  -  E
0x00011004 01 00 00 EA ... E
0x00011008 00 00 A0 E1 ..一个
0x0001100C 00 00 A0 E1 ..一个
0x00011010 02 00 00 EB ... E
0x00011014 0F 40万桶E8 @。è
0x00011018 00 00 A0 E1 ..一个
0x0001101C 00 00 A0 E1 ..一个


解决方案

由于ARM模式指令只能放在单词边界,也没有必要为en code中的地址的两个低位(他们会为0)。因此,在B指令的立即值是由2比特移位增量。对于第一个分支,三角洲是(目标 - PC )>> 2的目标是00011010和 PC 为00011004 + 8 = 0001100C。因此,三角洲 =(00011010-0001100C)>> 2 = 4 >> 2 = 1,您可以为第二个自己做数学题。

I do not understand the offset calcualted for the branch instructions (b and bl at addresses 0x00011004 and 0x00011010) related to the disassembled code listed below. I'm wondering that in the hex code listing the offsets seem to be 0x000001 and 0x000002. The Opcodes for the conditions b (EA) and bl (EB) were what I expected.

Thanks for every hint in advance

MyAssemblerFunc:
00011000  stmdb       sp!, {r0 - r3, lr} 
00011004  b           00011010 
00011008  mov         r0, r0 
0001100C  mov         r0, r0 
00011010  bl          |PrintHelloWorld ( 11020h )| 
00011014  ldmia       sp!, {r0 - r3, lr} 

Related Hex Code

0x00011000  0f 40 2d e9  .@-é
0x00011004  01 00 00 ea  ...ê
0x00011008  00 00 a0 e1  .. á
0x0001100C  00 00 a0 e1  .. á
0x00011010  02 00 00 eb  ...ë
0x00011014  0f 40 bd e8  .@.è
0x00011018  00 00 a0 e1  .. á
0x0001101C  00 00 a0 e1  .. á

解决方案

Since in ARM mode instructions can be placed only on word boundaries, there is no need to encode the two low bits of the address (they will be 0). Thus, the immediate value in the B instruction is the delta shifted by 2 bits. For the first branch, delta is (target - PC) >> 2. target is 00011010 and PC is 00011004+8 = 0001100C. So delta = (00011010-0001100C) >> 2 = 4 >> 2 = 1. You can do the math for the second one yourself.

这篇关于了解ARM汇编分公司偏移量计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆