Usually, we start coding with assembly and than we move to the embedded C code. In this case we first understand the embedded C code and than we will write the equivalent assembly code to mimic the same thing.
Embedded C code:
{
volatile unsigned int total, i;
total = 0; // initialize the total
for (i=0;i<5;i=i+1)
{
total = total + i;
}
return(0);
}
Result:
Assembly language code:
TTL transfer
AREA Myprog, CODE, READONLY
ENTRY
EXPORT main
main
MOVS R2, #0 ; Total = 0
MOVS R1, #0 ; i = 0
loop
ADDS R2, R2, R1 ; Total = Total + i
ADDS R1, R1, #1 ; i = i + 1
CMP R1, #5 ; compare i to 5
BLT loop ; if less than then branch to loop
done
SWI &11
END
Result:
No comments:
Post a Comment