在本练习中,我必须将该数组中的所有偶数都设置为0,但是当我运行程序时遇到了分段错误。有人能帮我吗?而且,如何在树莓派上打印结果?谢谢!
编辑:我已将注释从意大利语更改为英语。希望它更容易理解!
.data
v: .word 1,2,3,4,5,6,7,8 @ at the end I have to get 1,0,3,0,5,0,7,0
.text
.global main
main: mov r0, #8 @ dimension of my array
ldr r1, =v @ address of my array
push {lr}
mov r3, #4 @ index = 1
loop: cmp r3, #32 @ condition of the loop
bge exit @ if r3 is greather or equal exit from the loop
ldr r1, [r1, r3] @ load the element of my array of index r3 in r1
mov r1, #0 @ set my even element to 0
str r1, [r1, r3]
add r3, r3, #8 @ increment my index of 2 position
b loop @ back to loop function
exit: pop {pc} @ quit from my loop function and back to main
请问关于StackOverflow should be written in English的问题,其中包括源代码中的注释(最好还包括标签),因为这些注释对于试图帮助您使用代码的人们和您一样重要。幸运的是,我会说意大利语!
问题是您正在重新使用r1
。它保留您的数组指针,直到行
ldr r1, [r1, r3]
此时,它保存数组元素的内容。如果您再也不需要数组指针,那当然可以,但是您可以;和线
str r1, [r1, r3]
是一种无用的赠品,因为它试图将r1
的值存储在r1+r3
的值所给定的地址上,这不太可能是正确的,当然也不是您的情况。