Name:______________________________ Main Campus ...



Score:_________________Name:___________________________________________

ECE 2030 Final SPIM Programming Assignment

Due Monday, April 21

Counts as two MIPS programs

Write a MIPS program using SPIM to simulate a simple four-function integer calculator (ie. +,-*,/) with the following features:

1. Print out the title “Myname Four Function Calculator Program“

2. Space down a line & Prompt for input with “Input First Number “

3. Read in First Number and Push on Stack

4. Space down a line & Prompt for input with “Input Second Number “

5. Read in Second Number and Push on Stack

6. Space down a line & Prompt for input with “Input Operation (+,-,*,/) “

7. Perform a string read and determine the calculator operation with a series of nested IF statements (i.e. actually a CASE or SWITCH statement)

8. Compute X op Y (by selecting and calling one of four calculation subroutines)

9. Space down a line & Output “The answer is “

10. Output the answer by calling OUTPUT subroutine inside one of the four subroutines and space to the next line.

11. Loop back in the main program and restart the program at step 2

Additional Requirements: The main program must call one of four subroutines, ADD_SUB, SUB_SUB, MUL_SUB, or DIV_SUB, that computes the answer puts it in $a0 and calls the one OUT_SUB subroutine and then returns to the main program after printing out the answer. The values of the two numbers must be passed to the four subroutines on the stack (i.e. not in memory or in a register). Each of the four calculation subroutines will pop these values off the stack and load them into registers $a0 and $a1. Since the four calculation subroutines call another subroutine (for output) you will need to save and restore the return address on the stack in each one of these routines. You can assume the value of the answer is small enough so that it fits in 32-bits. The MIPS has multiply (MUL) and divide (DIV) pseudoinstructions but these cannot be used (Appendix A page A-56). These instructions would be a lot faster, but to learn how FOR loops work, you must perform multiply and divide in this program using loops. Place the subroutines in any order after the main program in your *.s SPIM source file. You should include a meta-language description of the program as comments in the assembly language source file.

Hints: Use the pcmip.s sample or your first lab program as a template or starting point. Review example stack and MIPS IF statement code from your class notes. The string read will return the ASCII value of the character for each calculator operation. An example MIPS loop can be found in pcmips.s. Set breakpoints, if your program does not work and follow execution with the single step command while checking the register values in the register window.

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download