练习ARM汇编语言,可以实现,循环输出数组中的数据,
想问,应该如何才能通过循环累加,把数组中的和求出,然后用输出显示出来
.data
fmt:.asciz "%10d\n"
ary:.word 0,1,2,3,4,5,6,7,8,9
.equ counter,( . - ary)/4
.text
.globl main
main:
stmfd sp!,{lr}
mov r4,#0
mov r6,#0
ldr r5, =ary
b testfor
loop:
ldr r0,=fmt
ldr r1,[r5],#4
bl printf
add r4,#1
testfor:cmp r4,#counter
blt loop
mov r0, #0
ldmfd sp!,{lr}
mov pc, lr
.end
输出的结果是:
0
1
2
3
4
5
6
7
8
9
我想要达到的结果,向下面这个C语言一样输出 ,sum
#include<stdio.h>
int main(){
int ary[10] = {0,1,2,3,4,5,6,7,8,9};
int sum, i;
sum = 0;
for ( i = 0; i < 10; i++)
{
sum =sum +ary[i];
}
printf("%10d\n",sum);
return 0;
}