Question: Write the following program using loops, branching and arithmetic instructions in MIPS: A custodial staff person at the College does a peculiar thing at night.

Write the following program using loops, branching and arithmetic instructions in MIPS:

A custodial staff person at the College does a peculiar thing at night. There is a corridor with a number of lights controlled by toggle switches. Initially all lights are off. Pressing the switch on a light will turn it on. Pressing it again will turn it off. This staff member walks down a corridor with n lights n times. On the ith trip the person only toggles the switches whose position number is divisible by i. When coming back to the initial position, the person does not press any switches. Write a MIPS assembly language program that determines the state (on or off) of the last light in the corridor after the staff member has made n trips up and down the corridor doing this routine.

Your program should prompt the user for the number of lights in the corridor, read the number and determine and print the value of the last light. You should print an error message if the user does not enter a positive integer. You are not required to have a loop for multiple runs, but I appreciate it when you do. If you use such a loop, you should terminate the loop with the user enters 0 for the number of lights.

Possible sample output:

Please enter a positive integer.

-3

This is not a positive integer. Please try again.

Please enter a positive integer.

3

The last bulb is off.

Please enter a positive integer.

0

Have a nice day.

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!