WordPress.com



Exercise2.1a.) f = g – h;b.) f = g + (h – 5);2.1.1 For the C statements above, what is the corresponding MIPS assembly code? Use a minimal number of MIPS assembly instructions.a.) sub f, g, h???????????? # The sum of g and h is placed in fb.) subi f, h, 5???????????? # Temporary variable f contains h – 5 addi f, f, g # the sum of f “(h-5)” and g in the place of f2.1.2 For the C statements above, how many MIPS assembly instructions are needed to perform the C statement?For f = g – h; you would only need one subtraction, so only one MIPS assembly instruction is needed. But for f = g + (h – 5); there is one addition and one subtraction, so we’ll need two MIPS assembly instructions.2.1.3 If the variables f, g, h, and i have values 1, 2, 3, and 4, respectively, what is the end value of f?The end values of f are:f = g – h; —-> f = 2 – 3 ——> f = -1f = g + (h – 5); ——-> f = 2 + ( 3 – 5) ——> f = 2 + (-2) —–> f = 0 even though there is a value for F to begin with, that doesn’t matter seeing as f is going to be over written.2.1.4 For the MIPS assembly instructions below, what is a corresponding C statement?a.) addi f, f, 4b.) add f, g, hadd f, i, fa.) f = f + 4;b.) f = g + h;???????????// (g + h) is being stored in the value of f f = i + f; // the value of f from the first statement is being added to i and stored in ff = i + (g + h);???????// same as the two before but is more readable 2.1.5 If the variables f, g, h, and i have values 1, 2, 3, and 4, respectively, what is the end value of f?a.) f = f + 4; —-> f = 1 + 4 —> f = 5b.) f = g + h; —–> f = 2 + 3 —-> f = 5 f = i + 5; ——> f = 4 + 5 —> f = 9f = i + (g + h); —-> f = 4 + (2 + 3) —-> f = 4 + 5 —–> f = 9Exercise 2.2a.) f = g – f;b.) f = i + (h – 2);2.2.1 For the C statements above, what is the corresponding MIPS assembly code? Use a minimal number of MIPS assembly instructions.a.) sub f, g, f??????????? # The sum of g and f is placed in fb.) subi f, h, 2????????????????? # Temporary varible f contains h – 2 add f, i, f???????????????????? # The sum of i and f is placed in f2.2.2 For the C statements above, how many MIPS assembly instructions are needed to perform the C statement?For f = g – f; there is only one subtraction so that’s going to be only one MIPS assembly instruction. For f = i + (h – 2); there is one addition and one subtraction, so there is going to be two MIPS assembly instructions.2.2.3?If the variables f, g, h, and i have values 1, 2, 3, and 4, respectively, what is the end value of f?a.) f = g – f; —> f = 2 – 1 —> f = 1b.) f = i + (h – 2); —> f = 4 + (3 – 2) —> f = 4 + 1 —> f = 52.2.4 For the MIPS assembly instructions below, what is a corresponding C statement?a.) addi f, f, 4b.) add f, g, hsub f, i, fa.) f = f + 4;b.)? f = g + h;?????????? // (g + h) is being stored in the value of f f = i – f; // the value of f from the first statement is being subtracted to i and stored in ff =? i – (g + h);???????// same as the two before but is more readable2.2.5?If the variables f, g, h, and i have values 1, 2, 3, and 4, respectively, what is the end value of f?a.) f = f + 4; —-> f = 1 + 4 —> f = 5b.) f = g + h; —> f = 2 + 3 —> f = 5 f= i – 5; —-> f = 4 – 5 —> f = -1f = i – (g + h); —-> f = 4 – (2 + 3) —> f = 4 – 5 —> f = -1Exercise 2.3a.) f = -g – f;b.) f = g + (-f – 5);2.3.1 For the C statements above, what is the corresponding MIPS assembly code? Use a minimal number of MIPS assembly instructions.a.) sub f, -g, f????????????? # The sum of -g and f is placed in fb.) subi f, -f, 5?????????? # Temporary variable f contains -f – 5 add f, g, t0?????????????????? # The sum of g and f is placed in f2.3.2?For the C statements above, how many MIPS assembly instructions are needed to perform the C statement?For f = -g – f it’s just one subtraction so that will be only one MIPS assembly instruction. For f = g + (-f – 5) that is one addition and one subtraction, so you will need two MIPS assembly instructions.2.3.3?If the variables f, g, h, i, and j have values 1, 2, 3, 4, and 5, respectively, what is the end value of f?a.) f = -g -f; —-> f = -2 – 1 —-> f = -3b.) f = g + (-f – 5); —> f =? 2 + (-1 – 5) —-> f = 2 + (-6) —> f = -42.3.4 For the MIPS statements below, what is a corresponding C statement?a.) addi f, f, -4b.) add i, g, hadd f, i, fa.) f = f + (-4);b.) i = g + h; // (g + h) is being stored in the value of if = i + f; // the value of f from the first statement is being added to i and stored in ff = (g + h) + f;?? // same as the two before but is more readable2.3.5 If the Variables f, g, h, and i have values 1, 2, 3, and 4, respectively, what is the end value of f?a.) f = 1 + (-4); —–> f = -3b.) i = g + h; —> i = 2 + 3 —> i = 5 f = i + f; —-> f = 5 + 1 —> f = 6f = (g + h) + f; —-> f = (2 + 3) + 1 —> f = 5 + 1 —-> f = 6Exercise 2.4Assumptions: variables f, g, h, i, and j are assigned to registers $s0, $s1, $s2, $s3, and $s4, respectively.Base address of the arrays A and B are in registers $s6 and $s7, respectively.a.) f = -g – A[4];b.) B[8] = A[i - j];2.4.1 For the C statements above, what is the corresponding MIPS assembly code?a.) lw?? $t0, 32($s6)??????????? ? # Temporary reg $t0 gets A[4] sub?? $s1, $zero, $s1??????????? #?Subtracting 0 – g to get -g, contained in $s1 sub $s0, $s1, $t0???????????????? # $s0(f) = $s1(-g) – $t0(A[4])b.) sub $t0, $s3, $s4????????????? # Temporary variable $t0 gets i –j, i is stored in $s3 and J is stored in $s4lw $t1, $t0($s6)?????????????????????? # Temporary variable $t1 gets A[i-j]sw $t1, 32($s7)????????????????????????# B[8] = A[i-j], Stores A[i-j] back into B[8]2.4.2 For the C statements above, how many MIPS assembly instructions are needed to perform the C statement?For both a) and b) there are 3 MIPS assembly instructions where needed to perform the C statement. Because we have to perform a (lw) transfer to a register first and then we perform a (sw) transfer back to the memory.2.4.3 For the C statements above, how many different registers are needed to carry out the C statement?For a) we used; $t0, $s6, $s1, $zero, $s0. Five different registers were need to carry out the C statement. For b) we used; $t0, $s3, $s4, $s1, $s6, $t1, $s7. Six different registers were needed to carry out the C statement.Excerise 2.6Assumptions: variables f, g, h, i, and j are assigned to registers $s0, $s1, $s2, $s3, and $s4, respectively.Base address of the arrays A and B are in registers $s6 and $s7, respectively.a.) f = f + A[2];b.) B[8] = A[i] + A[j];2.6.1 For the C statements above, what is the corresponding MIPS assembly code?a.) lw?? $s0, 4($s6)??????????? ? # Temporary reg $s0 gets A[2] sub $s0, $s0, $s1 #$s0(f) = $s0(A[2]) - $s1(f) add $s0, $s0, $s2???????????????? # $s0(f) = $s0(A[2]) + $s2(f)b.) add $t0, $s6, $s3????????????? # $t0 = $s6(A[2]) + $s3(i) lw $t0,0($t0)?????????????????????? # Temporary variable $t0 gets A[i] add $t1, $t0, $s7 #$t1 = $t0(A[i]) + $s7(A[j]) lw $s0, 4($t0)????????????????????????# B[8] = A[i] +A[j]2.6.2 For the C statements above, how many MIPS assembly instructions are needed to perform the C statement?For a) there are 3 MIPS assembly instructions where needed to perform the C statement. For b) there are 4 MIPS assembly instructions where needed to perform the C statement. Because we have to perform a (lw) transfer to a register first and sub and add operations.2.6.3 For the C statements above, how many different registers are needed to carry out the C statement?For a) we used; $s0, $s6, $s1, $s2. Four different registers were need to carry out the C statement. For b) we used; $t0, $t1, $s0, $s6, $s7. Five different registers were needed to carry out the C statement.Excerise 2.10a.) 00000 0010 0001 0000 1000 0000 0010 0000_twob.) 0000 0001 0100 1011 0100 1000 0010 0010_two2.10.1 For the binary entries above, what instruction do they represent?a.)0000 0010 0001 0000 1000 0000 0010 0000NameFormatoprsrtrdshamtfunct0000 0010 0001 00001000 0000 0010 00006 bits5 bits5 bits5 bits5 bits6 bitsaddR0161616032b.)0000 0001 01000 1011 0100 1000 0010 0010NameFormatoprsrtrdshamtfunct0000 0001 01000 1011 01001000 010 00106 bits5 bits5 bits5 bits5 bits6 bitssubR01052016342.10.2 What type (I-type, R-type, J-type) instruction do the binary entries above represent?As you can see from the table in 2.10.1 the op code for both a. and b. is 0, therefore they represent the R-type of format.2.10.3 If the binary entries above were data bits, what number wouuld they represent in hexadecimal?32168421a.)binary0000 0010 0001 00001000 0000 0010 0000deccimal0161616032hexadecimal010101002001011116 + 4 + 2 + 1 = 23b.)binary0000 0001 01000 1011 01001000 010 0010decimal0105201634hexadecimal0A51410220001114 + 2 + 1 = 7I labeled the top row 32, 16, 8, 4, 2, 1 then fill in the binary number below. If there is a 1 present you count it and if there is a 0 you don’t. Once you add them together you get the decimal conversion of the binary number. If the binary number is bigger than double the top row until you get the appropriate length.Excerise 2.11a.) 0x01084020b.) 0x025388222.11.1 What binary number does the above hexadecimal number represent?Using a hexadecimal converter I got a.) 1010 1110 0000 1011 1111 1111 1111 1100twob.) 1000 1101 0000 1000 1111 1111 1100 0000two2.11.2 What decimal number does the above hexadecimal number represent?Using a hexadecimal converter I got a.) 2920022012b.) 23661772162.11.3 What instruction does the above hexadecimal number represent?Using a hexadecimal converter I got a.) sw $t3, -4($s0)b.) lw $t0, -64($t0) ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download