Assignment 3

1 minute read

Due: by the end of the calendar day on Tuesday, September 24, 2024

A Python program to translate

The following Python program allows the user to continuously enter integers. Positive numbers are added to one accumulator, and negative numbers are added to another. In the end, both the positive and negative totals are displayed.

positive_total = 0
negative_total = 0

user_input = 1 #force the loop to run at least once

while user_input != 0:

    user_input = int(input("Enter an integer (0 to quit):"))

    if user_input > 0:
        positive_total += user_input
    else:
        negative_total += user_input

print("Positive total:",positive_total)
print("Negative total:",negative_total)

Here’s an example of a sample run in the console:

Enter an integer (0 to quit): 3
Enter an integer (0 to quit): -5
Enter an integer (0 to quit): 9
Enter an integer (0 to quit): 1
Enter an integer (0 to quit): -2
Enter an integer (0 to quit): 0
Positive total: 13
Negative total: -7

Assignment

Translate the above Python program into MIPS. When you run the program, the user interaction in the console should look like it does when you run the Python program.

Purpose

The purpose of this assignment is to get practice with branching. You don’t need to worry about having a copy of each variable in the .data section - if you keep track of a variable exclusively in a register, that is ok.

Grading

This is a 4-point assignment. See the rubric from the syllabus.

What to turn in

Turn in the following items

  1. Your .asm file which contains your MIPS program
  2. A .txt file (you can use Notepad, TextEdit, or even Visual Studio Code) where you paste in a sample run of your program that shows how it worked when you ran it in MARS

Where to turn it in

Submit your files to the Assignment 3 hand-in form on Blackboard.