为什么这段代码会在ARM中陷入无限循环 [英] Why this code run into infinite loop in ARM

查看:175
本文介绍了为什么这段代码会在ARM中陷入无限循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习ARM汇编并编译了一个代码,该代码只运行了5次循环,但是运行时进入了无限循环

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?

推荐答案

printf调用会破坏您的r1.将循环不变式保存在非临时寄存器中.

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

这篇关于为什么这段代码会在ARM中陷入无限循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆