Department of Information Technology

Assignment 2 Mobile Phones, Calculators, and SPIM's Memory-Mapped I/O

This is the last MIPS assignment. It is about writing a mini calculator simulator that is common in many mobile phones.

Goal : Learn how to write simple I/O routines in MIPS.

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 calculator

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.

Calculator

output control
0
123 <+> (add)
123+256 <*> (multiply)
379*1111 <y> (show result)
=421069 </> (divide)
421069/3 <y> (show result)
=140356 <n> (reset)
0 <+> (add)
3 <y> (add)
3 <x>
Good Bye!

Tips

  • 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. Write after 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".

Updated  2006-02-13 17:53:46 by Ahmed Rezine.