# divisor.s - A program that finds the sum of the proper divisors # of a positive integer, and then reports if the number is prime, # deficient, perfect or abundant. .data ask: .asciiz "Please enter a positive integer: " sum_is: .asciiz "The sum of the proper divisors is " is_prime: .asciiz "The number is prime, as well as deficient.\n" is_deficient: .asciiz "The number is deficient.\n" is_perfect: .asciiz "The number is perfect.\n" is_abundant: .asciiz "The number is abundant.\n" newline: .asciiz "\n" # Register allocation # $s0 = the user's number # $s1 = the proper sum of divisors .text main: li $v0, 4 # Ask for input number la $a0, ask syscall li $v0, 5 # Put user's input into $s0. syscall move $s0, $v0 move $a0, $s0 # Assign argument to function. jal proper # Put sum of proper divisors into $s1. move $s1, $v0 # Copy the return value. li $v0, 4 # Report sum of proper divisors. la $a0, sum_is syscall li $v0, 1 move $a0, $s1 syscall li $v0, 4 la $a0, newline syscall # ------------------------------------------------------------------- # If the sum of proper divisors ($s1) is 1, then the input is prime. # Otherwise, if $s1 < $s0, then the number is deficient. # Otherwise, if $s1 == $s, then the number is perfect. # Finally, if $s1 > $s0, then the number is abundant. bne $s1, 1, not_prime # Is the number prime? li $v0, 4 la $a0, is_prime syscall j done # After printing answer, go to the end. ############################################# # Insert the code to report if the number is # deficient, perfect or abundant. ############################################# done: li $v0, 10 syscall # ------------------------------------------------------------------- # Function proper: Find sum of the proper divisors of the number in # $a0, and report this result in $v0. Let's use t registers for # our own calculations. # $t0 = sum of proper divisors # $t1 = counter from 1 up to $a0-1 # $t2 = result of the remainder calculation proper: ############################################ # Insert the code to complete this function. ############################################