Question

Write an Assembley Language.A pair of numbers m and n are called "Perfect Dancing Partners" if...

Write an Assembley Language.A pair of numbers m and n are called "Perfect Dancing Partners" if the sum of all divisors of m (excluding m) is equal to the number n and the sum of all divisors of n (excluding n) is equal to m (with m ≠ n).

For example, the numbers 220 and 284 are perfect dancing partners because the only numbers that divide evenly into 220 are 1, 2, 4, 5, 10, 11, 20, 22, 44, 55, and 110 and 1+2+4+5+10+11+20+22+44+55 = 284. Similarly, the only numbers that divide evenly into 284 are 1,2,4,71, and 142 and 1+2+4+71+142 = 220.

Write an ASM app that accepts two numbers and asserts whether they are perfect dancing partners.

Other values to try are: (220, 284), (1184, 1210), (2620, 2924), (5020, 5564), (6232, 6368), (10744, 10856), (12285, 14595), (17296, 18416), (63020, 76084), and (66928, 66992).

Homework Answers

Answer #1

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.

-------------

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions