在手臂组件(分支)中查找机器代码



嘿,大家好,我试图将下面的代码转换为机器代码,但我卡住了.."分支指令的偏移量由汇编程序计算: – 通过取分支指令和目标地址之间的差值减去 8(以允许管道(。在某些幻灯片中找到此信息。根据这些信息,我假设 1.线路的地址是...4000 和 BNE 环路在 400c 中的地址。所以 4000-400c=-c 和 -c-8=-14.So 我认为机器码值应该是 0001 101 0 11111111111111111110100.最后一部分是偏移量,它的 -14 的 2 厘米。我不确定是真的吗?但也有一些资源说偏移值应该是-5,所以我不能确定。 这是空集

loop LDR R2,[R1],#4 ; Loading value from array and ;updating(increment) the address
ADD R3,R3,R2 ; Sum is stored in R3 register
SUB R0,R0,#1 ; Decrementing counter value
CMP R0,#00 ; Checking counter value
BNE loop
00002000 <loop>:
2000:   e4912004    ldr r2, [r1], #4
2004:   e0833002    add r3, r3, r2
2008:   e2400001    sub r0, r0, #1
200c:   e3500000    cmp r0, #0
2010:   1afffffa    bne 2000 <loop>

组装和链接。

1afffffa 条件 0b0001、0b1010 操作码,分支(非链接(立即签名 24

0xFFFFFA

<target_address>
Specifies the address to branch to. The branch target address is calculated by:
1. Sign-extending the 24-bit signed (two’s complement) immediate to 32 bits.
2. Shifting the result left two bits.
3. Adding this to the contents of the PC, which contains the address of the branch
instruction plus 8.

所以:

0xFFFFFFFA<<2 = 0xFFFFFFE8
0xFFFFFFE8+0x2010+8 = 0x2000

对象反汇编:

0xFFFFFFE8+0+8 = 0x0

要创建指令0x2000 - (0x2010+8( = 0xFFFFFFE8,0xFFFFFFE8>>2 = 0xFFFFFFFA,请0x00FFFFFA修剪为 24 位。 加上条件和0x1AFFFFFA。

对于这类东西,获取原始的ARM ARM,你可以从ARM找到的最接近的,而无需谷歌搜索非法副本,是获取ARMv5 ARM ARM,其中包括上面易于理解的描述。 有时ARMv7-AR更好,但很多时候原始的ARM ARM直系后代是最好的。

最新更新