decode ARM BL instruction

前端 未结 1 894
有刺的猬
有刺的猬 2021-01-07 04:49

I\'m just getting started with the ARM architecture on my Nucleo STM32F303RE, and I\'m trying to understand how the instructions are encoded.

I have running a simple

1条回答
  •  北海茫月
    2021-01-07 05:44

    bl is two, separate, 16 bit instructions. The armv5 (and older) ARM ARM does a better job of documenting them.

    111HHoffset11
    

    From the ARM ARM

    The first Thumb instruction has H == 10 and supplies the high part of the branch offset. This instruction sets up for the subroutine call and is shared between the BL and BLX forms.

    The second Thumb instruction has H == 11 (for BL) or H == 01 (for BLX). It supplies the low part of the branch offset and causes the subroutine call to take place.

    0xFA14 0xF000

    0xF000 is the first instruction upper offset is zeros 0xFA14 is the second instruction offset is 0x214

    If starting at 0x0800018c then it is 0x0800018C + 4 + (0x0000214<<1) = 0x080005B8. The 4 is the two instructions head for the current PC. And the offset is units of (16 bit) instructions.

    I guess the armv7-m ARM ARM covers it as well, but is harder to read, and apparently features were added. But they do not affect you with this branch link.

    The ARMv5 ARM ARM does a better job of describing what happens as well. you can certaily take these two separate instructions and move them apart

    .byte 0x00,0xF0
    nop
    nop
    nop
    nop
    nop
    .byte 0x14,0xFA
    

    and it will branch to the same offset (relative to the second instruction). Maybe the broke that in some cores, but I know in some (after armv5) it works.

    0 讨论(0)
提交回复
热议问题