Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

***I posted this in the morning, So if you want to look at this question fromm earlier the code works, But I amm missing the

***I posted this in the morning, So if you want to look at this question fromm earlier the code works, But I amm missing the error message part iff the uuser inputs anything <0 or>100 and the code that was answered before prime numbers 2,3,5,7 say they are not prime when they are and I was wondering if you could help me fix this. Thanks! Everything below is copy pasted from before when i asked this question i just need what i said above fixed if you could do that. thanks!

Good Afternoon, I been having trouble with getting this answer correct on Chegg and the past question i asked on this was just copy pasted and was incorrect. So whoever gets this couuld you please comment everything on the code and make sure it is very readable and follows the requirements. Thanks so much and will rate.

Given C code below:

#include  #include  #include  int main() { int input; int isPrime = 1; // Get user input printf("Welcome to Prime Tester "); printf("Enter a number between 0 and 100: "); scanf("%d", &input); // The code above this comment has been assembled by the professor // Test for valid input if(input < 0 || input > 100) { printf("Error: Invalid input for Prime Tester "); exit(0); } // Perform prime test if(input < 2) { isPrime = 0; } else if(input % 2 == 0 && input != 2) { isPrime = 0; } else { for(int x = 3; x <= sqrt(input); x += 2) { if(input % x == 0) { isPrime = 0; break; } } } // The code below this comment has been assembled by the professor // Display result if(isPrime == 1) { printf("The entered number is prime "); } else { printf("The entered number is not prime "); } return 0; }

as we can see my professor already did the top part and the bottom part. I just need the folloowing to be converted from C to MIPS.

*******Requirements Below:

Requirements

Convert the blocks of code (listed below) from the provided C program into the equivalent MIPS assembly code. Refer to the C Program tab in the Reference Material section for a listing of the entire C program. Students should refer to the List of Prime Numbers tab in the Reference Material section for help with testing their extra credit solution.

Request Input from User

  • Note 1: This section has been completed by the professor.
  • Note 2: The user's input is stored in register $a1.
 int input; int isPrime = 1; // Get user input printf("Welcome to Prime Tester "); printf("Enter a number between 0 and 100: "); scanf("%d", &input);

Test for Valid Input

  • Determine if the user's input (register $a1) falls outside the valid range
  • If the user's input is outside the valid range, move to the error label provided by the professor
 if(input < 0 || input > 100) { printf("Error: Invalid input for Prime Tester "); exit(0); }

Perform Prime Test

  • Determine if the user's input represents a prime number
  • To compute the square root of the user's input, call the calc_sqrt macro provided by the professor
    • The result of the calc_sqrt macro is stored in floating-point register $f2 for later use by the slt_sqrt macro
    • Example: calc_sqrt $rs
  • To test if a value is less-than or equal-to the square root value computed by the calc_sqrt macro, call the slt_sqrt macro provided by the professor
    • The result of the slt_sqrt macro is stored in register $v1
    • Example: slt_sqrt $rs
  • To display the prime or not prime messages, move to the isprime or notprime labels provided by the professor
 if(input < 2) { isPrime = 0; } else if(input % 2 == 0 && input != 2) { isPrime = 0; } else { for(int x = 3; x <= sqrt(input); x += 2) { if(input % x == 0) { isPrime = 0; break; } } }

Thanks so much again in advancced. C Language to MIPS and I will test it when you respond THANKS!

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

Structured Search For Big Data From Keywords To Key-objects

Authors: Mikhail Gilula

1st Edition

012804652X, 9780128046524

More Books

Students also viewed these Databases questions

Question

What is a verb?

Answered: 1 week ago

Question

What is Change Control and how does it operate?

Answered: 1 week ago

Question

How do Data Requirements relate to Functional Requirements?

Answered: 1 week ago