首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将链接寄存器设置到ARM组件中的标签

将链接寄存器设置到ARM组件中的标签
EN

Stack Overflow用户
提问于 2015-03-30 03:09:59
回答 1查看 216关注 0票数 1
代码语言:javascript
复制
_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中循环。

EN

回答 1

Stack Overflow用户

发布于 2015-03-30 03:21:46

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

代码语言:javascript
复制
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
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29333581

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档