Assigned 22 February, 2001

Due 1 March, 2001.

 

Write a function "atoi" that converts a string of up to 8 characters into a 32-bit integer.

int atoi(char str[]);

The string is ended with a null character (i.e., its ascii is 0), which could be the 9th character. You don’t need to check for errors in the string, i.e., you may assume the string contains only characters of ‘0’ through ‘9’.

Then write the main program, which calls the atoi function by placing the starting address of the string in $a0 and displays the returned integer value in the console window. You may use syscall 1 to display the integer value, as described in the textbook pages A-48 to A-49.

Your program must run in SPIM without error.

This assignment is the first part of a three-assignment series.

Submit your answers via EMAIL to chunfa@email.unc.edu by the beginning of class on the due date. Put HW5 in the subject line of your mail. Please make sure your email is in plain text format.


February 22, 2001 13:40