Assignment #3

Due September 24.

  1. Patterson and Hennessy exercises:

    2.6

    2.29

    2.30


  2. Write a SPIM program to print out all the prime numbers less than or equal to some number supplied by the user. Do not use Sieve of Eratosthenes.

  3. a) Write a SPIM program fragment to convert an ASCII decimal string to an integer. You should expect register $a0 to hold the address of a null-terminated string containing some combination of the digits 0 through 9. You should then parse this string to compute its integer equivalent and place this integer in register $v0. This will involve looping through the string and adding each digit times its place value to the total obtained so far. Your conversion algorithm need not handle negative numbers. If a nondigit character appears anywhere in the string, you should just stop, leaving the value -1 in register $v0. For example, if register $a0 points to a sequence of three bytes
    50 52 0
    
    which are the ascii codes for the null-terminated string "24", then when the program fragment stops register $v0 should contain the value 24.

    b) Now write a small shell so that your program prompts the user for a string and then prints out the integer result that you have obtained in $v0 (as an integer). Note that when you read strings from the console they will generally be terminated by a linefeed character (ascii 0a) rather than a null character, so that the above string would look like:

    50 52 0a
    
    Your shell just reads in the string "24" and prints out the integer 24.

    Submit only 3b.


  4. EXTRA CREDIT: Read 'The Single Instruction Computer' from the 'In More Depth' section of the CD. Then do 2.54 and 2.55.

Submit both electronic and printed copies of 2. and 3.