This **preview** has intentionally **blurred** parts. Sign up to view the full document

**Unformatted Document Excerpt**

230: CSE/EEE Computer Organization and Assembly Programming Assignment 2 Date assigned: September 24th, 2012 Due date: 4.30 pm, October 3rd, 2012 (at the start of the lecture) 1. [40 points] The following problems deal with translating from C to MIPS. Assume that the variables f, g, h, i, and j are assigned to registers $s0, $s1, $s2, $s3, and $s4, respectively. Assume that the base address of the array A and B are in registers $s6 and $s7, respectively. a f = -g - A[4]; b B[8] = A[i-j]; i. [10 points] For the C statements above, what is the corresponding MIPS assembly code? ii. [5 points] For the C statements above, how many MIPS assembly instructions are needed to perform the C statement? iii. [5 points] For the C statements above, how many different registers are needed to carry out the C statement? The following problems deal with translating from MIPS to C. Assume that the variables f, g, h, i, and j are assigned to registers $s0, $s1, $s2, $s3, and $s4, respectively. Assume that the base address of the arrays A and B are in registers $s6 and $s7, respectively. a sll $s2, $s4, 1 add $s0, $s2, $s3 add $s0, $s0, $s1 b add $t0, $s6, $s0 add $t1, $s7, $s1 lw $s0, 0($t0) addi $t2, $t0, 4 lw $t0, 0($t2) add $t0, $t0, $s0 sw $t0, 0($t1) iv. [10 points] For the MIPS assembly instructions above, what is the corresponding C statement? v. [5 points] For the MIPS assembly instructions above, rewrite the assembly code to minimize the number if MIPS instructions (if possible) needed to carry out the same function. vi. [5 points] How many registers are needed to carry out the MIPS assembly as written above? If you could rewrite the code, what is the minimal number of registers needed? 2. [35 points] In the following problems, we will be investigating memory operations in the context of an MIPS processer. The table below shows the values of an array stored in memory. Assume the base address of the array is stored in register $s6 and offset it with respect to the base address of the array. a Address Data 20 4 24 5 28 3 32 2 36 1 b Address Data 24 2 28 4 32 3 36 6 40 1 i. [10 points] For the memory locations in the table above, write C code to sort the data from lowest to highest, the placing lowest value in the smallest memory location shown in the figure. Assume that the data shown represents the C variable called Array, which is an array of type int, and that the first number in the array shown is the first element in the array. Assume that this particular machine is a byte-addressable machine and a word consists of four bytes. ii. [10 points] For the memory locations in the table above, write MIPS code to sort the data from lowest to highest, placing the lowest value in the smallest memory location. Use a minimum number of MIPS instructions. Assume the base address of Array is stored in register $s6. iii. [5 points] To sort the array above, how many instructions are required for the MIPS code? If you are not allowed to use the immediate field in lw and sw instructions, how many MIPS instructions do you need? The following problems explore the translation of hexadecimal numbers to other number of formats. a 0xabcdef12 b 0x10203040 iv. [5 points] Translate the hexadecimal numbers above into decimal. v. [5 points] Show how the data in the table would be arranged in memory of a little-endian and a big-endian machine. Assume the data is stored starting at address 0. 2. [30 points] The following problems explore number conversions from signed and unsigned binary numbers to decimal numbers. a 0010 0100 1001 0010 0100 1001 0010 0100 two b 0101 1111 1011 1110 0100 0000 0000 0000 two i. [5 points] For the patterns above, what base 10 numbers does the binary number represent, assuming that it is a twos complement integer? ii. [5 points] For the patterns above, what base 10 number does the binary number represent, assuming that it is an unsigned integer? iii. [5 points] For the patterns above, what hexadecimal number does it represent? The following problems explore number conversions from decimal to signed and unsigned binary numbers. a -1 ten b 1024 ten iv. [5 points] For the base ten numbers above, convert to 2s complement binary. v. [5 points] For the base ten numbers above, convert to 2s complement hexadecimal. vi. [5 points] For the base ten numbers above, convert the negated values from the table to 2s complement hexadecimal. ... View Full Document