SOLUTION :
.data
prompt:
.asciiz "Enter two numbers:\n"
output_y: .asciiz "The numbers
are perfect dancing numbers.\n"
output_n: .asciiz "The numbers
are not perfect dancing numbers.\n"
.text
.globl main
main:
# Prompt for user to enter 2 numbers
li $v0,4
la $a0,prompt
syscall
# Reading first number from the user
li $v0,5
syscall
move $t0,$v0
# Reading second number from the user
li $v0,5
syscall
move $t1,$v0
# Computing the sum of all divisors of the first
number
li $t2,1
# Divisor value
li $t3,0
# Sum of the divisors
again_1:rem $t4,$t0,$t2
# Dividing the number
bnez $t4,skip_1
# If remainder not equal to zero jump to label
skip
add $t3,$t3,$t2
# Else add the divisor to the sum variable
skip_1: addi $t2,$t2,1
# Increasing the divisor value
blt $t2,$t0,again_1 #
If divisor is less than continue in the loop
bne $t3,$t1,no
# If sum of the divisors of first number is not
equal to second number end the program with message
# Computing the sum of all divisors of the second
number
li $t2,1
# Divisor value
li $t3,0
# Sum of the divisors
again_2:rem $t4,$t1,$t2
# Dividing the number
bnez $t4,skip_2
# If remainder not equal to zero jump to label
skip
add $t3,$t3,$t2
# Else add the divisor to the sum variable
skip_2: addi $t2,$t2,1
# Increasing the divisor value
blt $t2,$t1,again_2 #
If divisor is less than continue in the loop
bne $t3,$t0,no
# If sum of the divisors of first number is not
equal to second number end the program with message
yes: li $v0,4
# Print this message to the user if 2 numbers
are perferct dancing partners
la $a0,output_y
syscall
b exit
no: li $v0,4
# Print this message to the user if 2 numbers
are perferct dancing partners
la $a0,output_n
syscall
exit: li $v0,10
# Exiting the program
syscall
OUTPUT :
Enter two numbers:
220
284
The numbers are perfect dancing numbers.
-------
Enter two numbers:
1184
1210
The numbers are perfect dancing numbers.
--------
Enter two numbers:
2620
2924
The numbers are perfect dancing numbers.
--------
Enter two numbers:
5020
5564
The numbers are perfect dancing numbers.
---------
Enter two numbers:
6232
6368
The numbers are perfect dancing numbers.
-----------
Enter two numbers:
10744
10856
The numbers are perfect dancing numbers.
-----------
Enter two numbers:
12285
14595
The numbers are perfect dancing numbers.
------------
Enter two numbers:
17296
18416
The numbers are perfect dancing numbers.
------------
Enter two numbers:
63020
76084
The numbers are perfect dancing numbers.
-------------
Enter two numbers:
66928
66992
The numbers are perfect dancing numbers.
-------------
Get Answers For Free
Most questions answered within 1 hours.