EE 361 Homework 3

Due Date: 9/12 (fri.)

Textbook Problem 3.1 (2 pt)

Textbook Problem 3.9 (1 pt)

Problem A (1 pt). [Do this problem after we cover PC relative addressing which is in the MPSb notes 23-25.]  Consider the following C language for-loop:

     for (i = 0; i < 100; i++) j = j + i;
The following is a MIPS assembly language implementation of the for-loop assuming that $3 and $4 are used to store i and j, respectively.
       add     $3,$0,$0     # i = 0;

Loop:  slti    $1,$3,100    # $1 = 1 if i < 100
       beq     $1,$0,Skip   # if $1 == 0 (i.e., i >= 100) then skip for-loop

       add     $4,$4,$3     # j = j + i;
       addi    $3,$3,1      # i++;
       beq     $0,$0,Loop   # go back to beginning of for-loop
Skip:
Write the machine code for the MIPS assembly language instructions. You may use decimal numbers (positive and negative ones) to fill in the fields. Note that all instructions and their machine code versions can be found in the back cover of the textbook.

Problem B. (1 pt.)

Consider the following C function:

     increasing(int i, int j, int k) /*  returns 1 if i < j < k */
     { if  (i < j && j < k) return 1;
       else return 0;
     }
Write a MIPS assembly language implementation of this function assuming

Problem C (3 pts total). The mcc compiler.

For this problem , you will be using the mcc compiler on wiliki to compile some simple C programs. The compiler is in the "~ee361/bin" directory in wiliki.  Set up a path to this directory by including the line

set path=($path ~ee361/bin)

into your  .cshrc  file.  You should log out and log in to activate this path.

Next, create the following simple C program and name it    test.c

main()
{
int x1, x2;
for (x1 = 0; x1 < x2; x1++) x2 = 2*x2;
}

Now compile the program by typing

mcc test.c

This will create a new assembly language file "test.s", which is the compiled version of "test.c". Examine "test.s" using an editor, e.g., "vi" or "pico". Notice it is a mix of