Write an ARMv7 assembly program that uses a loop to generate

Write an ARMv7 assembly program that uses a loop to generate the integers from 1 to 15, inclusive, summing the odd integers in that range.

(a) Your loop should generate all of the integers in the range of 1 to 15, not just the odd integers.

(b) The final result should be in register R0.

It should contain

.global _start

_start:

Solution

Before Writing a program in ARMv7 assembly language lets take an example by using C language

In this We want to find 1 +2+ 3 + 4+5 + ..... + 15. So here we will need a loop where n starts at 1 and goes up to 15. Getting the not just the odd integers values, we can see that if we go 1by 1, we are getting 1,2, 3,4, 5, .... Each time, we will add the value of n into the sum by saying:

sum = sum + n;

#include <stdio.h>

int main (void)

{

int n, sum;

/* initialize sum to zero */

sum = 0;

/* construct a for loop to arrange the value of n where n starts at 1 and goes up to 15*/

for (n = 1; n <= 15; n = n + 1)

{

sum = sum + n;

}

printf(\"\ The sum of integers from 1 to 15 is %d\", sum);

return(0);

}

The following translates this into the instructions supported by ARMv ARMv7 assembly language.

               MOV      R0, #0         ; R0 accumulates total

              MOV R1, #1        ; R1 counts from 1

again ADD R0, R0, R1

               SUBS R1, R1, #1

               BNE again

   halt B halt           ; infinite loop to stop computation

Write an ARMv7 assembly program that uses a loop to generate the integers from 1 to 15, inclusive, summing the odd integers in that range. (a) Your loop should
Write an ARMv7 assembly program that uses a loop to generate the integers from 1 to 15, inclusive, summing the odd integers in that range. (a) Your loop should

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site