Why this code run into infinite loop in ARM

大憨熊 提交于 2020-04-07 05:17:25

问题


I am learning ARM assembly and compiled a code which simply ran a loop 5 times but when ran it goes to infinite loop

.global main
main:
push {ip.lr}
sub r1,r1,r1
well:
ldr r0,=message
bl printf
add r1,r1,#1
cmp r1,#6
bne well
pop {ip,pc}
message:
       .ascii "Amit Singh Tomar\n"

Why this code runs in to infinite Loop?


回答1:


printf call destroys your r1. Save your loop invariant in non-scratch register.




回答2:


R1 gets trashed by the call to printf - use a non-volatile register instead or save/restore R1 around the call to printf.



来源:https://stackoverflow.com/questions/22552833/why-this-code-run-into-infinite-loop-in-arm

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!