_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中循环。
发布于 2015-03-30 03:21:46
不要使用mov pc, lr继续,因为这些不是子例程。只需使用一个简单的无条件分支back,例如:
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 nexthttps://stackoverflow.com/questions/29333581
复制相似问题