将链接寄存器设置为ARM程序集中的标签

时间:2015-03-29 19:09:59

标签: assembly arm

_start:
     mov    r0, #0                 @ Function number (index) to use
     mov    r1, #3                 @ First parameter
     mov    r2, #2                 @ Second parameter
     bl     arithfunc              @ Call the function

     swi    0x11                   @ Terminate

arithfunc:
     cmp    r0, #num_func
     bhs    DoAND                  @ If code is >=7, do operation 0
     adr    r3, JumpTable          @ Get the address of the jump table
     ldr    pc, [r3,r0,lsl #2] @ Jump to the routine (PC = R3 + R0*4)
     add    r0,r0, #1
     bne arithfunc

JumpTable:                             @ Table of function addresses
     .word  DoAND
     .word  DoOR
     .word  DoEOR
     .word  DoANDNOT
     .word  DoNOTAND
     .word  DoNOTOR
     .word  DoNOTEOR
DoAND:
     and    r11,r1,r2
     mov    pc, lr                 @ Return

DoOR:
     orr    r11,r1,r2             @ Operation 1 (R0 = R1 - R2)
     mov    pc,lr                  @ Return
DoEOR:
     eor    r11,r1,r2
     mov    pc,lr

如何将lr设置为不仅在一次运行后终止?

它向上运行直到DoAND:并返回到开头。我知道这是它的工作方式,但我无法通过其他任何方式找到它。

我试图让它循环通过arithfunc。

1 个答案:

答案 0 :(得分:2)

不要使用mov pc, lr继续,因为这些不是子程序。只需使用简单的无条件分支,例如:

arithfunc:
     cmp    r0, #num_func
     bhs    DoAND                  @ If code is >=7, do operation 0
     adr    r3, JumpTable          @ Get the address of the jump table
     ldr    pc, [r3,r0,lsl #2] @ Jump to the routine (PC = R3 + R0*4)
next:
     add    r0,r0, #1
     bne arithfunc

JumpTable:                             @ Table of function addresses
     .word  DoAND
     .word  DoOR
     .word  DoEOR
     .word  DoANDNOT
     .word  DoNOTAND
     .word  DoNOTOR
     .word  DoNOTEOR
DoAND:
     and    r11,r1,r2
     b next

DoOR:
     orr    r11,r1,r2             @ Operation 1 (R0 = R1 - R2)
     b next

DoEOR:
     eor    r11,r1,r2
     b next
相关问题