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.

Assignment

Write a program that asks for a string as input. The string should contain two numbers separated by a "+" character. The string is at most 80 characters (including null byte which marks the end of the string). The program will then rewrite the string and the result. 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-tabel to perform the translation. You can find this tabel in many books, or at asciitable.

After a run, the program will ask the user if he wants a new addition to be performed, the answer "y/n" tells the program if he should begin again or exit.

In case the input is corrupted, the program should return a message like in the following examples.

Example of a run of the programm :

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!

Tasks

The program should use at least two procedures: check_string and int_to_string. You have to start from this file addition.s.

Updated  2006-02-13 17:55:30 by Ahmed Rezine.