Question: Using MIPS assembly language, prompts the user to enter an integer, calculates the sum of the factors of this integer, and determines whether the integer

Using MIPS assembly language, prompts the user to enter an integer, calculates the sum of the factors of this integer, and determines whether the integer is perfect. If the integer is not perfect, determine if it is prime or not.

I just need to add codes that determine if user's input is prime or not; everything else is coded.

.data prompt: .asciiz "Enter an integer value: " factor_sum: .asciiz "The sum of the factors is: " perfect: .asciiz "The number is perfect." not_perfect: .asciiz "The number is not perfect."

prime_msg: .asciiz "The number is prime." not_prime_msg: .asciiz "The number is not prime."

.text .globl main

main: # Display prompt and read in number li $v0, 4 la $a0, prompt syscall li $v0, 5 syscall move $t0, $v0 # $t0 contains the user input # Calculate sum of factors li $t1, 1 # Initialize sum to 1 # Loop through possible divisors li $t2, 2 loop_factors: ble $t2, $t0, continue_factors # If $t2 > $t0, exit loop div $t0, $t2 mfhi $t3 # $t3 contains the remainder beq $t3, $0, add_factor # If remainder is 0, add divisor to sum addi $t2, $t2, 1 # Increment divisor j loop_factors add_factor: add $t1, $t1, $t2 # Add divisor to sum addi $t2, $t2, 1 # Increment divisor j loop_factors continue_factors: # Print sum of factors li $v0, 4 la $a0, factor_sum syscall move $a0, $t1 li $v0, 1 syscall # Check if number is perfect sub $t4, $t1, $t0 beq $t4, $t0, number_is_perfect # If number is not perfect, check if it is prime li $t5, 2 # Initialize divisor to 2 loop_prime: bgt $t5, $t0, number_is_not_perfect # If divisor > number, number is prime div $t0, $t5 mfhi $t6 # $t6 contains the remainder beq $t6, $0, number_is_not_perfect # If remainder is 0, number is not prime addi $t5, $t5, 1 # Increment divisor j loop_prime # If number is not prime, it is not perfect li $v0, 4 la $a0, not_perfect syscall li $v0, 10 # Exit program syscall number_is_perfect: # If number is perfect, print message li $v0, 4 la $a0, perfect syscall li $v0, 10 # Exit program syscall number_is_not_perfect: # If number is not prime, print message li $v0, 4 la $a0, not_perfect syscall li $v0, 10 # Exit program syscall

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!