问题描述
我不明白为与下面列出的反汇编代码相关的分支指令(地址 0x00011004 和 0x00011010 处的 b 和 bl)计算的偏移量.我想知道在列出偏移量的十六进制代码中似乎是 0x000001 和 0x000002.条件 b (EA) 和 bl (EB) 的操作码符合我的预期.
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}
相关十六进制代码
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 .. á
推荐答案
由于在 ARM 模式下指令只能放置在字边界上,因此不需要对地址的两个低位进行编码(它们将为 0).因此,B 指令中的立即数是移位 2 位的增量.对于第一个分支,delta 是 (target - PC) >> 2.target 是 00011010 和 PC 是 00011004+8 = 0001100C.所以delta = (00011010-0001100C) >> 2 = 4 >> 2 = 1.你可以自己计算第二个.
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 汇编器分支偏移计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!