Assigned: 23 September 2004

Due: 30 September 2004

Write a function “atoi” that converts a string of up to 8 ASCII digits into a 32-bit integer.

int atoi(char str[]);

The string ends with a null character (i.e., its ASCII code 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.

23 September 2004