gpt4 book ai didi

arm - 在 ARM/Thumb(Android) 上解码 BLX 指令

转载 作者:行者123 更新时间:2023-12-04 04:51:18 24 4
gpt4 key购买 nike

我想在 arm 上解码 blx 指令,我在这里找到了一个很好的答案:
Decoding BLX instruction on ARM/Thumb (IOS)

但在我的情况下,我一步一步地遵循这个提示,得到了错误的结果,谁能告诉我为什么?

这是我的测试:

.plt: 000083F0  sub_83F0       ...
...
.text:00008436 FF F7 DC EF BLX sub_83F0

我通过以下方式解析机器代码“FF F7 DC EF”:
   F7 FF EF DC

11110 1 1111111111 11 1 0 1 1111101110 0
S imm10H J1 J2 imm10L

I1 = NOT(J1 EOR S) = 1
I2 = NOT(J2 EOR S) = 1

imm32 = SignExtend(S:I1:I2:imm10H:imm10L:00)
= SignExtend(1111111111111111110111000)
= SignExtend(0x1FFFFB8)
= ?

所以偏移量是0xFFB8?
但是 0x83F0-0X8436-4=0xFFB6
我需要你的帮助!!!

最佳答案

当 BLX 的目标是 32 位 ARM 代码时,BLX 中编码的立即数指令添加到 align(PC,4) ,不是 PC 的原始值.

  • PCBLX 执行期间指令是 0x8436 + 4 == 0x843a由于ARM管道
  • align(0x843a, 4) == 0x8438

  • 所以:
  • 0x00008438 + 0ffffffb8 == 0x83f0

  • ARM ARM 在 <label> 的汇编语法中提到了这一点。部分指令:

    For BLX (encodings T2, A2), the assembler calculates the required value of the offset from the Align(PC,4) value of the BLX instruction to this label, then selects an encoding that sets imm32 to that offset.



    对齐要求也可以通过仔细阅读ARM ARM中的Operation伪代码找到:
    if ConditionPassed() then
    EncodingSpecificOperations();
    if CurrentInstrSet == InstrSet_ARM then
    next_instr_addr = PC - 4;
    LR = next_instr_addr;
    else
    next_instr_addr = PC;
    LR = next_instr_addr<31:1> : ‘1’;
    if toARM then
    SelectInstrSet(InstrSet_ARM);
    BranchWritePC(Align(PC,4) + imm32); // <--- alignment of the current PC when BLX to non-Thumb ARM code
    else
    SelectInstrSet(InstrSet_Thumb);
    BranchWritePC(PC + imm32);

    关于arm - 在 ARM/Thumb(Android) 上解码 BLX 指令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17398343/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com