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

1. Convert the following Java if statements to MIPS Assembly code.  You may assume variables are stored in registers of your choice, but you must list your assumptions.  Assume x, y, and z are integers.
    a) if(x >= y) System.out.println("x is greater than or equal to y");
    b) if(x < y && y < z)
            System.out.println("x is less than z");
    c) if(y > x || z <= x)
            System.out.println("x might be greater than z");
       else
             System.out.println("x is greater than or equal to y and less than z");
    d) if( (x + y) <= z && (x * y) <= z)
          System.out.println("" + (x+y) + " is less than or equal to " + z + " as is " + (x*y));

2. Convert the following MIPS operations to binary and then to hex.
    a) sub $s2, $t3, $t5
    b) addi $t1, $s2, 127
    c) lw $s3, 12($s4)
    d) or $t3, $t4, $t5

3. Write a MIPS program that allows a user to find the area of a triangle or the area of a rectangle.  The user should be able to choose the type of shape he/she wishes to use.  You may use integer input such as 1 for a triangle or 2 for a rectangle.  You must then read in the height and width of the rectangle or the height and base of the triangle and output the result. It is highly recommended that you write this program in C first.

4. Write MIPS statements for the following floating point C/Java statements.  You may use registers from the MIPS co-processor 1 and memory locations as necessary.
    a) x = x + 0.332
    b) y = ( 6.2 * y - x ) / 31.02
    c) z = 5.0 / 3.0 * 4.0 + 1.0
    d) f = a + b * c / 4.13f

5.  Convert the following logical expressions to assembly. You may use pseudo-instructions.
    a) x < y && y < z
    b) x <= y || y <= z
    c) x | y & z
    d) (a + b) < (c / d)