Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Looking for help with an ARM assembly program. The instructions are as follows:

ID: 3543597 • Letter: L

Question

Looking for help with an ARM assembly program. The instructions are as follows:

A prime number n is a natural number (i.e. a non-negative integer) which is greater than

1 and is not divisible by any other natural number other than 1 and n. In other words, n has

no non-trivial factors other than 1 and n. So for example, 2 is the smallest prime number.

To test whether a natural number n is a prime number or not, you can set up a loop to test

every natural number between 1 and n (i.e. natural numbers from 2 to n 1) one by one

to see whether n is divisible by any of them and count the number of non-trivial factors for

n you have seen in the whole process. If n is not divisible by any of them, the number of

non-trivial factors for n is 0 and n is a prime number; otherwise n is not a prime number.

Assignment

You are to nd all prime numbers between 1 and n, where n is entered by the user. Your

program should:

prompt the user to input a natural number n,

determine and display all the prime numbers between 1 and n in increasing order, and

print the number of primes found between 1 and n.

Your program must have at least two functions:

isprime should accept one parameter, x and return 0 or 1, indicating whether or not x is

prime.

divide should accept two parameters, x and y and should return the quotient and remainder

(as two separate integers) found by dividing x by y.

Also the divide function is as follows and must be used as such in a seperate file:


.text

.globl divide

divide: mov r2, r1 @move divisor (y) to r2

mov r1, r0 @move dividend (x) to r1

mov r0, #0 @clear r0 to accumulate result

mov r3, #1 @set bit 0 in r3

start: cmp r2, r1 @y < x?

movls r2, r2, lsl#1 @shift y left until y >= x

movls r3, r3, lsl#1 @also shift r3 left until y >= x

bls start @keep shifting until y >= x

loop: cmp r1, r2 @carry set if r1>r2

subcs r1, r1, r2 @if r1>r2 then r1 -= r2

addcs r0, r0, r3 @if r1>r2 then r0 += r3

movs r3, r3, lsr#1 @shift r3 right

movcc r2, r2, lsr#1 @if r3 > 0 then shift r2 right

bcc loop @if r3 == 0 then we are done

mov pc, lr @quotient is in r0, and

@remainder is in r1

.end

Explanation / Answer

Is prime function:


INPUT "Choice ",R9

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote