Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Principles Programming And Performance

Authors: Patrick O'Neil, Elizabeth O'Neil

2nd Edition

1558605800, 978-1558605800

More Books

Students also viewed these Databases questions

Question

4 Learn the distinction between real GDP and nominal GDP

Answered: 1 week ago

Question

What is the importance of qualitative data in HR analytics?

Answered: 1 week ago