Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write an assembly language program which will prompt the user for a non-negative decimal integer n and determine whether or not n is prime. (You

Write an assembly language program which will prompt the user for a non-negative decimal integer n and determine whether or not n is prime. (You will need to do a bit of research regarding algorithms that can be used to test numbers to see if they are prime.) The program must display the number input and the result of the test on the screen, then prompt the user to enter another number. For example, if the user entered the numbers 7 and 100, the screen output produced by your program should appear as follows: Enter a non-negative integer (0 to exit): 7 7 is a prime number. Enter a non-negative integer (0 to exit): 100 100 is not a prime number; it is divisible by 2.

The input number may obviously consist of varying numbers of digits; leading zeroes may be entered by the user, but are not to be displayed on your output line. The input number is to be stored as an unsigned 32-bit (doubleword) value (legal input is any decimal integer value between 0 and 232-1). The program should terminate when the user enters 0, and should generate an error message if the user enters non-numeric input or a negative number. The prime number test must be done in a separate procedure that is called from the main program; the single argument (the number to be checked for primality) must be passed to this procedure on the stack, and a result code must be returned to the caller in the EAX register. The value returned in EAX must be 0 if the users number is prime, and must be a divisor of the users number if it is composite (if the number has multiple divisors, any one of them may be returned as proof of nonprimality). In the special case that the user enters the number 1, return 1 (note that the number 1 is not prime by definition, since it does not have two distinct divisors.) No other registers may be changed by the prime check procedure, so use the stack to save and restore any registers your procedure uses, other than EAX. Your called procedure must create a base pointer which is used to reference its input parameter as well as the local variables (if any) that it creates, and must restore the callers base pointer before returning.

Your program must also measure the elapsed time, in milliseconds, taken to check each (legal) input value for primality. You should do this by calling Irvines GetMseconds procedure twice: once after the input is error-checked, but before the prime number procedure is called; and again just after the prime number procedure returns. The difference between the second value and the first will give you the run time in milliseconds, assuming that you did not commence your program run shortly before midnight (correction for midnight rollover is a desirable, but not required, feature of your program). In addition to outputting whether or not the number is prime, your program should also display the run time in milliseconds for each computation. For example: Enter a non-negative integer (0 to exit): 1046527 1046527 is a prime number. This computation took 15 milliseconds. Enter a non-negative integer (0 to exit): 4 4 is not a prime number; it is divisible by 2. This computation took 0 milliseconds.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

3. How frequently do the assessments occur?

Answered: 1 week ago