Skip to main content
Department of Information Technology

Assignment 1 MIPS: Addition and strings

Goal :

  • Learn more about MIPS assembly language by using SPIM input system calls for characters and strings.
  • Write subroutines for !!converting strings to numbers and vice versa.

Obs :

  • Please follow the guidelines provided here for submission.
  • Deadlines: first deadline 2010-10-03 23.59, completion 2010-10-10 23.59
  • It is important that you have been through the tutorial and the lab.

Task

You are supposed to start from the following file addition.s and write a program that asks for a string as input. The string should contain a set of numbers separated by a "+" character, and is at most 80 characters long (including null byte which marks the end of the string).
The program will then rewrite the string and the result of the sum. In order to handle input and output operations, you should only use the system calls read_string and print_string described in the SPIM-manual, pages A-48 - A-49.

After each run, the program is supposed to ask the user if he wants to perform a new addition, and then waits for the answer "y/n" telling it to restart the procedure or exit.

In case the input is corrupted, the program should return an error message (see the example below).

A small part of the solution is already included in the given file. Your task consists in implementing the subroutines check_string and int_to_string according to the given description, and to implement the rest input/output operations and the actual sum computations.

Hints

The program does not have to handle numbers bigger than 2147483647 that is (2^31 - 1), thus you should only use the system calls read_string and print_string. In the SPIM-manual, pages A-48 - A-49 you can find informations about these system calls (syscalls).

An important part of the problem is to translate the content of the string, and to build a new one, from a number. You will also need the ASCII-table to perform the translation. You can find this table in many books, or at asciitable.

In order to compute the sum, it is recommended that you implement it separately in a subroutine which takes as input a valid string and returns the result. In such a case, you will have only to handle the input/output operations and subroutine calls in the main.

Example of a run of the program

      Give an addition:
      123+456+789
      The sum is: 123+456+789=1368
      Do you want to perform another addition? (y/n) y

      Give an addition:
      123+456+789+10000+20000
      The sum is: 123+456+789+10000+20000=31368
      Do you want to perform another addition? (y/n) y

      Give an addition:
      hej+hopp
      Corrupted input!
      Do you want to perform another addition? (y/n) y

      Give an addition:
      123++456
      Corrupted input!
      Do you want to perform another addition? (y/n) y

      Give an addition:
      123+456+
      Corrupted input!
      Do you want to perform another addition? (y/n) n

      Good bye!

Good Luck!!

Updated  2010-09-25 15:21:27 by David Eklöv.