Question: Exercise 2.6 The following problems deal with translating from C to MIPS. Assume that the variables f, g, h, i, and j are assigned to
Exercise 2.6 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 arrays A and B are in registers $s6 and $s7, respectively.
a. f = –g + h + B[1];
b. f = A[B[g]+1];
2.6.1 [10] <2.2, 2.3> For the C statements above, what is the corresponding MIPS assembly code?
2.6.2 [5] <2.2, 2.3> For the C statements above, how many MIPS assembly instructions are needed to perform the C statement?
2.6.3 [5] <2.2, 2.3> For the C statements above, how many registers are needed to carry out the C statement using MIPS assembly code?
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. add $s0, $s0, $s1 add $s0, $s3, $s2 add $s0, $s0, $s3
b. addi $s6, $s6, –20 add $s6, $s6, $s1 lw $s0, 8($s6)
2.6.4 [5] <2.2, 2.3> For the MIPS assembly instructions above, what is the corresponding C statement?
2.6.5 [5] <2.2, 2.3> For the MIPS assembly above, assume that the registers $s0, $s1, $s2, $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 the assembly code.
2.6.6 [10] <2.3, 2.5> For each MIPS instruction, show the value of the op, rs, and rt fi elds. For I-type instructions, show the value of the immediate fi eld, and for the R-type instructions, show the value of the rd fi eld.
Exercise 2.7 The following problems explore number conversions from signed and unsigned binary number to decimal numbers.
a. 1010 1101 0001 0000 0000 0000 0000 0010two
b. 1111 1111 1111 1111 1011 0011 0101 0011two 2.7.1 [5] <2.4> For the patterns above, what base 10 number does it represent, assuming that it is a two’s complement integer?
2.7.2 [5] <2.4> For the patterns above, what base 10 number does it represent, assuming that it is an unsigned integer?
2.7.3 [5] <2.4> 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. 2147483647ten
b. 1000ten 2.7.4 [5] <2.4> For the base ten numbers above, convert to two’s complement binary.
2.7.5 [5] <2.4> For the base ten numbers above, convert to two’s complement hexadecimal.
2.7.6 [5] <2.4> For the base ten numbers above, convert the negated values from the table to two’s complement hexadecimal.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
