Why this code run into infinite loop in ARM

后端 未结 2 507
梦毁少年i
梦毁少年i 2021-01-22 01:54

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,r         


        
相关标签:
2条回答
  • 2021-01-22 02:18

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

    0 讨论(0)
  • 2021-01-22 02:39

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

    0 讨论(0)
提交回复
热议问题