Fordham, New York City's Jesuit University
back Back to course home page
FORDHAM UNIVERSITY CISC 3593
Fordham College Lincoln Center Computer Organization
Dept. of Computer and Info. Science Spring, 2011



Homework Assignment 4
Due date: March 1

Exercise 2.1

The following problems deal with translating from C to MIPS. Assume that the variables g, h, i, and j are given and already stored in registers, and could be considered as 32-bit integers as declared (e.g. using int) in a C program. Let f, g, etc., stand for registers in the MIPS code you write.

a. f = g + h + i + j;

b. f = g + (h + 5);

2.1.1
[5 pts.] <§2.2>For the C statements above, what is the corresponding MIPS assembly code? Use a minimum number of MIPS assembly instructions.

2.1.3
[5 pts.] <§2.2>If the variables f, g, h, i, and j initially have values 1, 2, 3, 4, and 5, respectively, what is the end value of f after each C statement?

The following problems deal with translating MIPS to C. Assume that the variables f, g, and h are given and represent specific registers in the MIPS code, and could be considered as 32-bit integers as declared in a C program. (Modified slightly from problem in text.)

a. add f, g, h

b. addi f, g, 1
  add f, f, h

2.1.4
[5 pts.] <§2.2>For the MIPS statements above, what is a corresponding C statement? Give a single C statement for each case.

2.1.5
[5 pts.] <§2.2>If the variables f, g, and h initially have values 1, 2, and 3 respectively, what is the end value of f in each case? Treat the two cases (a and b) as independent, not sequential.

Exercise 2.2

The following problems deal with translating from MIPS to C. Assume that the variables f and h are given and represent specific registers in the MIPS code, and could be considered as 32-bit integers as declared in a C program.

a. add f, f, h

b. sub f, $0, f
  addi f, f, 1

2.2.4
[5 pts.] <§2.2>For the MIPS statements above, what is a corresponding C statement? Give a single C statement for each case.

2.2.5
[5 pts.] <§2.2>If the variables f and h initially have values 1 and 3 respectively, what is the end value of f in each case? Treat the two cases as independent, not sequential.

Exercise 2.4

The following problems deal with translating from C to MIPS. Assume that the variables f, g, and h are assigned to registers $s0, $s1, and $s2, respectively. Assume that A and B are arrays of 32-bit integers and that their base addresses are in registers $s6 and $s7 respectively. Make use of temporary registers as needed, but use only the minimum necessary. Treat the two statements as independent, not sequential.

a. f = g + h + B[4];

b. f = g - A[B[4]];

2.4.1
[10 pts.] <§§2.2, 2.3>For each of the C statements above, what is the corresponding MIPS assembly code?

2.4.2
[5 pts.] <§§2.2, 2.3>For each of the C statements above, how many MIPS assembly instructions are needed to perform the C statement? (The answers follow from your answers to 2.4.1.)

2.4.3
[5 pts.] <§§2.2, 2.3>For each of the C statements above, how many different registers are needed to carry out the C statement? (The answers follow from your answers to 2.4.1.)

Exercise 2.6

The following problems deal with translating from MIPS to C. Assume that the variables f, g, h, and i are assigned to registers $s0, $s1, $s2, and $s3 respectively. Assume that A is an array of 32-bit integers and that its base addresses is in register $s6. (Modified slightly from problem in text.)

a. add $s0, $s3, $s2
  add $s0, $s0, $s3
  add $s0, $s0, $s1

b. addi $s6, $s6, -20
  add $s6, $s6, $s1
  lw $s0, 8($s6)

2.6.4
[10 pts.] <§§2.2, 2.3>For each set of MIPS assembly instructions above, what is the corresponding C statement? Write a single C statement for each case.

2.6.5
[5 pts.] <§§2.2, 2.3>For the MIPS assembly instructions above, assume that the registers $s0, $s1, $s2, and $s3 contain the values 10, 20, 30, and 40, respectively. Also, assume that register $s6 contains the value 256, and that memory contains the following values:

Address Value
256 100
260 200
264 300

Find the value of $s0 at the end of execution of the assembly code in each case.


Robert Moniot 2011-02-18