基本上我正在尝试在ARM中创建一个for循环 这将循环10次,并在每个循环中将用户输入作为整数收集,还添加每个用户输入并打印出所有用户输入的总数。
使用我发布的这段代码,我得到了用户输入的无限循环
.file "sum.s"
.text
.align 2
.global main
.type main, %function
/* main() sums 10 values from stdin and prints the sum */
main:
push {lr} // save lr
//Code goes here
mov r3, #0 // i = 0
loop:
cmp r3, #10
beq done // if i == 10 goto print
//reads user input
sub sp, sp, #4
ldr r0, =rdfmt
mov r1, sp
bl scanf
ldr r4, [sp]
add sp, sp, #4
add r2, r4, r2 //sum += user input
add r3, r3, #1 //i = i+1 counter
b loop
done:
ldr r0, =prtfmt
mov r1, r2
bl printf
//End of my code
pop {pc} // put lr in pc
.section .rodata
rdfmt: .asciz "%d"
prtfmt: .asciz "sum is %d\n"