Write a program to add ten numbers from 0 to 10 or Convert following C language to ARM assembly Language.
void main()
{
int sum;
int i;
sum =0;
for (i=0;i <10;i++)
{
sum = sum +1;
}
}
--------------------------------------------
AREA myData, DATA
COUNT EQU 10 ; we will test count upto 10
SUM EQU 0
AREA MYCODE, CODE
ENTRY
EXPORT __main
__main
LDR r0,=COUNT
LDR r1, =SUM
LDR r2, =1 ;r2 stores the initial vale of i Myloop
myloop
ADD r1, r2, r1 ;sum = i + sum
SUBS r3, r0, r2 ; r3 = r0-r2 (check if r0 and r2 are equal)
BEQ stop ;Branch to stop label if r0-r2=0, Z=1
ADD r2, r2, #1 ; increment i
BNE myloop ; if flag not set then do the loop again
stop
B stop
END
No hay comentarios.:
Publicar un comentario