02~Chapter 2

02~Chapter 2 - 2 Solutions Solution 2.1 2.1.1 a. add f, g,...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 2 Solutions Solution 2.1 2.1.1 a. add f, g, h add f, f, i add f, f, j b. addi f, h, 5 addi f, f, g 2.1.2 a. 3 b. 2 2.1.3 a. 14 b. 10 2.1.4 a. f = g + h b. f = g + h 2.1.5 a. 5 b. 5 Solution 2.2 2.2.1 a. add f, f, f add f, f, i b. addi f, j, 2 add f, f, g S20 Chapter 2 Solutions 2.2.2 a. 2 b. 2 2.2.3 a. 6 b. 5 2.2.4 a. f += h; b. f = 1f; 2.2.5 a. 4 b. Solution 2.3 2.3.1 a. add f, f, g add f, f, h add f, f, i add f, f, j addi f, f, 2 b. addi f, f, 5 sub f, g, f 2.3.2 a. 5 b. 2 2.3.3 a. 17 b. 4 Chapter 2 Solutions S21 2.3.4 a. f = h g; b. f = g f 1; 2.3.5 a. 1 b. Solution 2.4 2.4.1 a. lw $s0, 16($s7) add $s0, $s0, $s1 add $s0, $s0, $s2 b. lw $t0, 16($s7) lw $s0, 0($t0) sub $s0, $s1, $s0 2.4.2 a. 3 b. 3 2.4.3 a. 4 b. 4 2.4.4 a. f += g + h + i + j; b. f = A[1]; S22 Chapter 2 Solutions 2.4.5 a. no change b. no change 2.4.6 a. 5 as written, 5 minimally b. 2 as written, 2 minimally Solution 2.5 2.5.1 a. Address Data 12 1 8 6 4 4 0 2 temp = Array[3]; Array[3] = Array[2]; Array[2] = Array[1]; Array[1] = Array[0]; Array[0] = temp; b. Address Data 16 1 12 2 8 3 4 4 0 5 temp = Array[4]; Array[4] = Array[0]; Array[0] = temp; temp = Array[3]; Array[3] = Array[1]; Array[1] = temp; 2.5.2 a. Address Data 12 1 8 6 4 4 0 2 temp = Array[3]; Array[3] = Array[2]; Array[2] = Array[1]; Array[1] = Array[0]; Array[0] = temp; lw $t0, 12($s6) lw $t1, 8($s6) sw $t1, 12($s6) lw $t1, 4($s6) sw $t1, 8($s6) lw $t1, 0($s6) sw $t1, 4($s6) sw $t0, 0($s6) b. Address Data 16 1 12 2 8 3 4 4 0 5 temp = Array[4]; Array[4] = Array[0]; Array[0] = temp; temp = Array[3]; Array[3] = Array[1]; Array[1] = temp; lw $t0, 16($s6) lw $t1, 0($s6) sw $t1, 16($s6) sw $t0, 0($s6) lw $t0, 12($s6) lw $t1, 4($s6) sw $t1, 12($s6) sw $t0, 4($s6) Chapter 2 Solutions S23 2.5.3 a. Address Data 12 1 8 6 4 4 0 2 temp = Array[3]; Array[3] = Array[2]; Array[2] = Array[1]; Array[1] = Array[0]; Array[0] = temp; lw $t0, 12($s6) lw $t1, 8($s6) sw $t1, 12($s6) lw $t1, 4($s6) sw $t1, 8($s6) lw $t1, 0($s6) sw $t1, 4($s6) sw $t0, 0($s6) 8 mips instructions, +1 mips inst. for every non- zero offset lw/sw pair (11 mips inst.) b. Address Data 16 1 12 2 8 3 4 4 0 5 temp = Array[4]; Array[4] = Array[0]; Array[0] = temp; temp = Array[3]; Array[3] = Array[1]; Array[1] = temp; lw $t0, 16($s6) lw $t1, 0($s6) sw $t1, 16($s6) sw $t0, 0($s6) lw $t0, 12($s6) lw $t1, 4($s6) sw $t1, 12($s6) sw $t0, 4($s6) 8 mips instructions, +1 mips inst. for every non- zero offset lw/sw pair (11 mips inst.) 2.5.4 a. 305419896 b. 3199070221 2.5.5 Little-Endian Big-Endian a. Address Data 12 12 8 34 4 56 0 78 Address Data 12 78 8 56 4 34 0 12 b. Address Data 12 be 8 ad 4 f0 0 0d Address Data 12 0d 8 f0 4 ad 0 be Solution 2.6 2.6.1 a. lw $s0, 4($s7) sub $s0, $s0, $s1 add $s0, $s0, $s2 b. add $t0, $s7, $s1 lw $t0, 0($t0) add $t0, $t0, $s6 lw $s0, 4($t0) S24 Chapter 2 Solutions 2.6.2 a. 3 b. 4 2.6.3 a. 4 b. 5 2.6.4 a. f = 2i + h; b. f = A[g 3]; 2.6.5 a. $s0 = 110 b. $s0 = 300 2.6.6 a....
View Full Document

Page1 / 50

02~Chapter 2 - 2 Solutions Solution 2.1 2.1.1 a. add f, g,...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online