Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

MARS MIPS simulator Write a MIPS code that checks all numbers between 1 and 1000

ID: 3766333 • Letter: M

Question

MARS MIPS simulator

Write a MIPS code that checks all numbers between 1 and 1000 and finds the maximum number of steps required to reach to 1 from a staring number in this range. Hold the maximum in register $s1.

To help you with this question, we provided the Python code below: = 0 # number of maximum steps. Hold this value in $s1 for i in range(1, 1001): temp 1 step 0 while temp-1: if temp % 2-0: temp - temp/2 else: temp = (3 *temp) + 1 step +1 if step > max: max = step Note: Instead of the above code, you can turn your code in part (a) to a function (find steps0) and implement like this: max0 for i in range(1, 1001) step find if step > max: _steps(i) max -step

Explanation / Answer


n = input() # read a positive integer n from the user sumOfDivisors = 0 for i in range(1, n): # go from 1 to n-1 if n % i == 0: # if i is a divisor sumOfDivisors += i if sumOfDivisors == n: print "1" else: print "0"