C++ and MIPS
For this and all programming assignments for this course, you are to write a MIPS assembly language program
that can be loaded and executed using the MARS simulator.
For now, I want your programs confined to the core instruction set of the MIPS processor. All of the instructions
we have discussed to date are in the core instruction set. Using the MARS Help facility, you can find these listed
under “Basic Instructions”. (You’ll see a large number of instructions there that use “$f..” registers or mention
“FP” in the description. Those are floating point instructions. You can ignore them.)
To insure that your program uses only core instructions, go to the “Settings” menu on MARS and make sure the
checkbox labeled “Permit extended (pseudo) instructions and formats” is NOT checked. This way MARS will
insure you don’t accidentally use a pseudoinstruction.
The program is simple, at least in C++. The first thing I want you to do is write and debug the program in C++.
Here’s what the program should do:
1. When prompted, the user will simply input numbers, each followed by Enter (or Return). Your program
will prompt the user by outputting a question mark followed by a space.
2. Normally, every time the user inputs a number, the program will respond by displaying the smallest and
largest numbers seen so far. Both numbers should be displayed on the same line, with the first number
followed by a comma and a space, then the second number, then endl.
3. After the smallest and largest values are displayed, the user will be prompted for the next number.
4. An exception to 2 and 3 above happens when the user enters the number -32768. When this number is
entered should display, the sum of the values that have been entered (excluding -32768), after which the
program should terminate.
Here’s a Sample program session:
Of course, after you have your C++ program completed, the fun begins. You need to translate the C++ code to
MIPS assembly language, then test and debug using the MARS simulator until the program works correctly.
Make sure your source file has the extension “.asm”.
Note that your C++ code should be included in comments, as in my examples.