Assignment 2 Mobile Phones, Calculators, and SPIM's Memory-Mapped I/O
Goal : Learn how to write simple I/O routines in MIPS.
This is the last MIPS assignment. It is about writing a mini calculator simulator that is common in many mobile phones.
All input and output must follow the so-called memory-mapped I/O (or polling) scheme. You will implement it in this assignment. All you need to know about is in section A.8 of Hennessy and Patterson.
Pay a special attention to the last part. Note the difference between the memory mapped approach and the interrupts approach. You will be implementing memory mapped I/O; interrupts are also possible in SPIM, but coding them is longer and harder.
Only correct input will be accepted, and in simple mobile phones this means only numbers 0,1,2,...,9, and the operations +,-,* and /. Three more characters will be used y = "Yes" button, n = "No" button, and x = "Exit program" button (see example bellow). All the other characters will be ignored.
Only integers are accepted by the program. The program needs not calculate operations which lead to a result bigger than 2147483647 (2^31 - 1). Moreover, you are not allowed to use I/O system calls (syscalls) like in the previous assignment.
The bold text and the one between "< >" represent the input. The characters in the control column, ex <y> (show result), are "invisible" characters: they are not to be printed. Only the left column are to be printed.
|379*1111||<y> (show result)|
|421069/3||<y> (show result)|
- Start from the following file calculator.
- It can be tricky to get the memory mapped input/output to work. Therefore, it is recommended to divide the programming into two steps. Write and test the polling I/O routines first (fill in the "readCharacter" and "printCharacter"). Then, write the rest of the program/simulator that uses these routines.
- First you should, as you know : THINK FIRST before begining the coding ! This will save you plenty of time. In this assignment you have much freedom for the code structure. The program can of course use the procedure int_to_string (from the previous assingment). You could write most of the program in main, or use routines to divide the solutions into smaller parts.
- Optional improvment: manage overflow. In case of an overflow the program can print a messsage; for example "Too large value entered".