ECE 232: Homework # 3 Due March 1 Compile your code in SPIM and verify your answers. Your codes should contain appropriate assembler directives. SPIM is available at http://pages.cs.wisc.edu/~larus/spim.html 1. [10 pts] What is the difference between pseudo instruction and real instruction? Can a MIPS machine execute pseudo instructions? Consider a pseudo instruction: la $rs, addr, which loads the 32-bit address addr into register $rs. Implement this instruction with real MIPS instructions. 2. [10 pts] Assume that the address of a[0], b[0], and c[0] are in registers $s0, $s1 and $s2. i is in $s3 and j is in $s4. Translate the following into MIPS assembly code: j=0; for (i = 10; i >= 2; i--) { a[i] = 2*b[i] + c[i] - 5; j = j + a[i]; } 3. [10 pts] Translate the following into MIPS assembly code: if (i < 6) j = j else if (i j = j else j = j + 8; == 6) - 7; / 3; Assume that variable i is in register $s0 and j is in register $s1. 4. [15 pts] Translate the following into MIPS assembly code i=0; while ((a[i] >= 15) && (i < 12)) { i = i+3; b[i] = b[i] - a[i]; } Assume that the memory address of a[0] is in register $s0 and that of b[0] is in register $s1. Assume i is in register $s3. 5. [10 pts] Translate the following into MIPS assembly code switch (i) { case 0: j = 5; break; case 1: ; case 2: j = 9; break; case 3: j = 3; break; case 4: j = 11; break; default: j = 7; } Assume i is in $s1 and j is in $s2; 6. [15 pts] This question deals with matrix multiplication: for (i=0; i<n; i++) { for (j=0; j<n; j++) { for (k=0; k<n; k++) { c[i][j] = c[i][j] + a[i][k]*b[k][j]; } } } For multiplication, use mult instruction, not the pseudo-instruction mul. You can assume that the numbers involved are small enough that the results of each multiplication can be held in just 32 bits. Assume that the addresses of a[0][0], b[0][0], and c[0][0] are held in registers $t1, $t2 and $t3, respectively. Assume i, j, and k are stored in $s1, $s2, and $s3, respectively. Each matrix is stored in row-major order, i.e., entries in the first row are stored first, followed by the second row and so on. The value of n is stored in register $s0. Translate this into MIPS code and verify your answer. Use for example, n=5, a[i][j]=i+n*j, b[i][j]=1. 7. [20 pts] Translate the following code into MIPS code: sum = 10; for (i=0; i<n; i++) if (isEven(i)) sum += i; int isEven(int i) return ( i & 1); Assume sum is in $s1, i is in $t0, n is in $t1; 8. [10 pts] Suppose the content of $s1 = 0x12344321. Then you execute the instruction addi $s1, $s1, 0xdcba. What is the value of $s1 after executing the addi instruction?