Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given Code Below: .data .align 0 # Define strings used in each of the printf statements msg1: .asciiz Welcome to Prime Tester msg2: .asciiz

Given Code Below:

.data .align 0

# Define strings used in each of the printf statements msg1: .asciiz "Welcome to Prime Tester " msg2: .asciiz "Enter a number between 0 and 100: " msg3: .asciiz "Error: Invalid input for Prime Tester " msg4: .asciiz "The entered number is prime " msg5: .asciiz "The entered number is not prime " ec_msg: .asciiz " is prime " # Reserved for use in extra credit

.align 2 .text .globl main

# The following macros are provided to simplify the program code # A macro can be thought of as a cross between a function and a constant # The assembler will copy the macro's code to each use in the program code # Display the %integer to the user # Reserved for extra credit .macro display_integer (%integer) li $v0, 1 # Prepare the system for output add $a0, $zero, %integer # Set the integer to display syscall # System displays the specified integer .end_macro # Display the %string to the user .macro display_string (%string) li $v0, 4 # Prepare the system for output la $a0, %string # Set the string to display syscall # System displays the specified string .end_macro # Compute the square root of the %value # Result stored in the floating-point register $f2 .macro calc_sqrt (%value) mtc1.d %value, $f2 # Copy integer %value to floating-point processor cvt.d.w $f2, $f2 # Convert integer %value to double sqrt.d $f2, $f2 # Calculate the square root of the %value .end_macro # Determine if the %value is less-than or equal-to the current square root value in register $f2 # Result stored in the register $v1 .macro slt_sqrt (%value) mtc1.d %value, $f4 # Copy integer %value to floating-point processor cvt.d.w $f4, $f4 # Convert integer %value to double c.lt.d $f4, $f2 # Test if %value is less-than square root bc1t less_than_or_equal # If less-than, go to less_than_or_equal label c.eq.d $f4, $f2 # Test if %value is equal-to square root bc1t less_than_or_equal # If equal-to, go to less_than_or_equal label li $v1, 0 # Store a 0 in register $v1 to indicate greater-than condition j end_macro # Go to the end_macro label less_than_or_equal: li $v1, 1 # Store a 1 in register $v1 to indicate less-than or equal-to condition end_macro: .end_macro

main: # This series of instructions # 1. Displays the welcome message # 2. Displays the input prompt # 3. Reads input from the user display_string msg1 # Display welcome message display_string msg2 # Display input prompt li $v0, 5 # Prepare the system for keyboard input syscall # System reads user input from keyboard move $a1, $v0 # Store the user input in register $a0 j student_code # Go to the student_code label

error: display_string msg3 # Display error message j exit isprime: display_string msg4 # Display is prime message j exit notprime: display_string msg5 # Display not prime message exit: li $v0, 10 # Prepare to terminate the program syscall # Terminate the program

Above is all the given code that we do not modify. We need to add all requuired code below that.

Below is what needs to be added below the given code.

image text in transcribed

image text in transcribed

**If possible could you do it in Mars so that I could make sure it works completely with correct syntax. Aswelll as can you common what all of the new code does for each required part thankks! Last thing can you put the required code that is asked above below the given code.

Thanks for all the help in advanced! Will rate. Would like it asap or by tomorrow if possible. Doesnt seem to hard I am just not comfortable with this language yet. Thanks

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 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

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

Database Principles Programming And Performance

Authors: Patrick O'Neil

1st Edition

1558603921, 978-1558603929

More Books

Students also viewed these Databases questions