为什么这个BNE [ARMv7]指令似乎已经超出了我的功能

时间:2013-12-13 01:08:30

标签: arm

以下是生成的ARM指令:

0000a138(2): e52db004   PUSH {r11}
0000a13c(2): e28db000   ADD r11, SP, #0
0000a140(2): e24dd00c   SUB SP, SP, #12
0000a144(2): e50b0008   STR r0, [r11, #-8]
0000a148(2): e50b100c   STR r1, [r11, #-12]
0000a14c(2): e51b3008   LDR r3, [r11, #-8]
0000a150(2): e3530000   CMP r3, #0
0000a154(2): 1a000004   BNE #+16             <-----
0000a158(2): e51b3008   LDR r3, [r11, #-8]
0000a15c(2): e1a00003   MOV r0, r3
0000a160(2): e28bd000   ADD SP, r11, #0
0000a164(2): e8bd0800   POP {r11}
0000a168(2): e12fff1e   BX LR

BNE进入PC + 16:

  • 这是:CURRENT_ADDRESS + 8 + 16
  • 这是:0xa154 + 24
  • 即:0xa16c

此地址在函数结束后

以下是生成它的C:

int silly(int a, int b)
{
start:
    if (!a)
        return a;
    a = 0;
    goto start;
}

1 个答案:

答案 0 :(得分:0)

看起来我确定函数结束的方法是错误的。

以下是objdump的完整功能反汇编:

0000a138 <silly_add>:
    a138:   e52db004    push    {fp}        ; (str fp, [sp, #-4]!)
    a13c:   e28db000    add fp, sp, #0
    a140:   e24dd00c    sub sp, sp, #12
    a144:   e50b0008    str r0, [fp, #-8]
    a148:   e50b100c    str r1, [fp, #-12]
    a14c:   e51b3008    ldr r3, [fp, #-8]
    a150:   e3530000    cmp r3, #0
    a154:   1a000004    bne a16c <silly_add+0x34>
    a158:   e51b3008    ldr r3, [fp, #-8]
    a15c:   e1a00003    mov r0, r3
    a160:   e28bd000    add sp, fp, #0
    a164:   e8bd0800    pop {fp}
    a168:   e12fff1e    bx  lr
    a16c:   e3a03000    mov r3, #0
    a170:   e50b3008    str r3, [fp, #-8]
    a174:   eafffff4    b   a14c <silly_add+0x14>