=========================preview======================
(COMP180)comp180_00s_midterm_sol.pdf
Back to COMP180 Login to download
======================================================
Midterm Examination
Solution and Marking Scheme
1.
d (4 points)

2.
a (4 points)

3.
e (4 points)

4.
(14 points total) a) For a given program, let N denote the total number of instructions, NA the number of


class A instructions, NB the number of class B instructions, and NC the number of class C instructions. CPU time = CPU clock cycles / clock rate CPU time on M1 using C1 = (4 NA + 6 NB + 8 NC) / 400 msec
= (4 x 0.3 + 6 x 0.5 + 8 x 0.2) N / 400 msec = 5.8 N / 400 msec (1.5 points) CPU time on M2 using C1 = (2 x 0.3 + 4 x 0.5 + 3 x 0.2) N / 200 msec = 3.2 N / 200 msec (1.5 points) Thus, using C1, M1 is 6.4 / 5.8 or 32 / 29 times as fast as M2. (1.5 points) b) CPU time on M1 using C2 = (4 x 0.3 + 6 x 0.2 + 8 x 0.5) N / 400 msec = 6.4 N / 400 msec (1.5 points) CPU time on M2 using C2 = (2 x 0.3 + 4 x 0.2 + 3 x 0.5) N / 200 msec = 2.9 N / 200 msec (1.5 points) Thus, using C2, M2 is 6.4 / 5.8 or 32 / 29 times as fast as M1. (1.5 points) c) CPU time on M1 using C3 = (4 x 0.5 + 6 x 0.3 + 8 x 0.2) N / 400 msec
= 5.4 N / 400 msec (1.5 points) C3 is the best choice since the CPU time for the program on M1 using C3 is the shortest. (1 point)
d) CPU time on M2 using C3 = (2 x 0.5 + 4 x 0.3 + 3 x 0.2) N / 200 msec
= 2.8 N / 200 msec (1.5 points) C3 is the best choice since the CPU time for the program on M2 using C3 is the shortest. (1 point)
5. (10 points total) Let N denote the total number of instructions in the program. CPU time = CPU clock cycles / clock rate CPU time on M1 = N / 400 msec (4 points) CPU time on M2 = (5 x 0.2 + 4 x 0.1 + 4 x 0.5 + 3 x 0.15 + 3 x 0.05) N / 200 msec
= N / 50 msec
Thus, M1 is 400 / 50 or 8 times as fast as M2.
6. (10 points total)
This pseudoinstruction
ble $s0, $s1, L

can be implemented as
slt $t0, $s1, $s0
beq $t0, $zero, L

7. (15 points total)
add $t1, $zero, $zero
add $t2, $t0, $zero

Loop: slti $t3, $t1, 10
beq $t3, $zero, Exit
addi $t4, $t1, 1
sw $t4, 0($t2)
addi $t1, $t1, 1
addi $t2, $t2, 4
j Loop

Exit:

(4 points)
(2 points)
# $t1 = i = 0
# $t2 = address of a[0]
# $t3 = 1 if i < 10
# Exit loop if i >= 10
# $t4 = i + 1
# a[i] = i + 1
# $t1 = i + 1
# $t2 = $t2 + 4

8. (15 points total) a)
Inputs Outputs
a b CarryIn CarryOut Sum
0 0 0 0 0
0 0 1 0 1
0 1 0 0 1
0 1 1 1 0
1 0 0 0 1
1 0 1 1 0
1 1 0 1 0
1 1 1 1 1

(5 points)
b) Sum = (a . b . CarryIn) + (a . b . CarryIn) + (a . b . CarryIn) + (a . b . CarryIn) (5 points) [underline denotes NOT]

9. (12 points total)
a) Bit 31 Bits 30-23 Bits 22-0 : 0 : 01111110 : 11111111111111111111111 (1 point) (2 points) (2 points)
b) x = -24 (3 points)

c) With the biased notation, floating-point numbers can be compared in magnitude (e.g, for sorting) simply by performing integer comparison without having to compute the actual values of the floating-point numbers. (4 points)
10. (12 points to