Homework 5
CS 345
Computer Organization
10 Points
Due Friday, Feb. 27, 2015 at the beginning of class
You must submit either a soft or hard copy of this assignment and show all work!

Write the code for each problem in C first and convert it to MIPS.

1. Write a MIPS program that uses an if-elseif-else statement to compute the perimeter of a triangle or a rectangle given an input of 1 or 2, respectively  Provide an error statement that indicates if the user has entered incorrect input.

2.  Write a loop in MIPS assembly to determine if two strings are the same length.  Hint: you can find the length of a string by counting all the characters up to the null character.  Remember that the null character has a value of zero. 

3.  Write a MIPS program to compute the product of all the elements in an array.  Be sure to use registers to store both the length of the array and the array itself.  Hint: this program will be very similar to the Summation.asm program on the example code page.

4.  Write a for loop in MIPS to print every other character in a string starting with the first character.  You should not need to store the length of the string.

5.  Convert the following instructions from MIPS assembly to binary and then to hex.  Be sure to use the green sheet to help you with your conversions.  You may use MARS to help you find your answers.

and $s1, $s2, $s3

or $s1, $s2, $s3

addi $s1, $t1, 18

sub $t3, $s2, $t5