BLX
带返回和状态切换的跳转指令,此指令只适用 ARMv5T*, ARMv6*, ARMv7。
BLX (immediate)
Branch with Link calls a subroutine at a PC-relative address.
Branch with Link and Exchange Instruction Sets (immediate) calls a subroutine at a PC-relative address, and changes instruction set from ARM to Thumb, or from Thumb to ARM.
带链接的分支调用PC相对地址处的子程序。
带链接和交换指令集的分支(立即)调用PC相对地址处的子程序,并将指令集从ARM更改为Thumb,或从Thumb更改为ARM。
ARM指令是4字节对齐,最低两位可以用作状态指示,如果最低两位是0,表示切换到ARM状态。
BLX<c> <label>
BLX (register)
Branch with Link and Exchange (register) calls a subroutine at an address and instruction set specified by a register.
带链接和交换(寄存器)的分支在寄存器指定的地址和指令集调用子例程。
BLX<c> <Rm>
blx immediate :
10534: b580 push {r7, lr}
10536: b082 sub sp, #8
10538: af00 add r7, sp, #0
1053a: 6078 str r0, [r7, #4] /* this 指针 */
printf("%d, %d\n", v1, v2);
1053c: 687b ldr r3, [r7, #4] /* r3 = this */
1053e: 6819 ldr r1, [r3, #0] /* r1 = [r3+0] = v1 */
10540: 687b ldr r3, [r7, #4] /* r3 = this */
10542: 685b ldr r3, [r3, #4] /* r3 = [r3+4] = v2 */
10544: 461a mov r2, r3 /* r2 = r3 = v2 */
10546: f240 50a8 movw r0, #1448 /* r0 = 0x5a8 */
1054a: f2c0 0001 movt r0, #1 /* r0 = (1 << 16) | 0x05a8 = 0x105a8,此为数据段地址 */
1054e: f7ff ef38 blx 103c0 <printf@plt> /* printf(r0, r1, r2) */
blx register :
104dc: e51b3008 ldr r3, [fp, #-8] ; x
104e0: e1a03103 lsl r3, r3, #2 ; r3 = x << 2 , [0, 4, 8]
104e4: e24b2004 sub r2, fp, #4 ; r2 = fp - 4
104e8: e0823003 add r3, r2, r3 ; r3 = r2 + r3 [0|4|8] --> (fp-4)+[0|4|8]
104ec: e5133014 ldr r3, [r3, #-20] ; 0xffffffec r3 = 0:[(fp-4)-20], 1:[(fp-4)+4-20], 2:[(fp-4)+8-20]
104f0: e50b300c str r3, [fp, #-12] ; save function address, 0:r3=(fp-24), 1:r3=(fp-20), 2:r3=(fp-16)
f();
104f4: e51b300c ldr r3, [fp, #-12] ; load function address
104f8: e12fff33 blx r3 ; execl