=========================preview======================
(COMP180)COMP180-final-00-sol.pdf
Back to COMP180 Login to download
======================================================
Final Examination
Solution and Marking Scheme
1.

a) B (2 points) b) C (2 points) c) E (2 points) d) A (2 points) e) D (2 points)
2.
a) CPI of P1: 2 x 0.4 + 3 x 0.3 + 4 x 0.2 + 5 x 0.1= 3.0 (1 point) CPI of P2: 2 x 0.4 + 2 x 0.3 + 3 x 0.2 + 4 x 0.1= 2.4 (1 point)
b) Let IC denote the instruction count. MIPS = IC / (CPU time x 106) = IC / (IC x CPI x cycle time x 106) = clock rate in MHz / CPI
MIPS of P1: 100 / 3 = 33.3 (1 point) MIPS of P2: 120 / 2.4 = 50 (1 point)
c) P2 is 50 / 33.3 = 1.5 times faster than P1. (1 point)
d) CPI of P1 (new compiler): 2 x 0.5 + 3 x 0.35+ 4 x 0.1 + 5 x 0.05 = 2.7 (1 point)
e) MIPS of P1 (new compiler): 100 / 2.7 = 37.04 (1 point)
f) P1 (new compiler) is (100 / 2.7) / (100 / 3) = 1.1 times faster than P1 (old compiler). (1 point)
g) Since CPU time = IC x CPI x cycle time, the conditions are:
same instruction count (1 point)
same cycle time (1 point)
3. (10 points)
addi $s2, $zero, 0 # initialize byte count to 0
Loop: lbu $t2, 0($t0) # load byte from 1st str
beq $t2, $zero, Exit # exit if it is a null char
lbu $t3, 0($t1) # load byte from 2nd str
bne $t2, $t3, Exit # exit if characters differ
addi $s2, $s2, 1 # increment byte count
addi $t0, $t0, 1 # increment 1st str pointer
addi $t1, $t1, 1 # increment 2nd str pointer
j Loop
Exit:
OK to use lbins tead of lbu.
4.

addi opcode (6), reg1 (5), reg2 (5), constant (16) (1 point) slt opcode (6), reg1 (5), reg2 (5), reg3 (5), shamt (5), funct (6) (1 point) bne opcode (6), reg1 (5), reg2 (5), offset (16) (1 point) add opcode (6), reg1 (5), reg2 (5), reg3 (5), shamt (5), funct (6) (1 point) j opcode (6), offset (26) (1 point)
5.
a) 100011two = -29ten (0.5 point)
111101two = -3ten (0.5 point)
Sum = 100000two (1 point)
Has carry out (1 point)
No overflow (1 point)
b) 101101two = -19ten (0.5 point)
110001two = -15ten (0.5 point)
Sum = 011110two (1 point)
Has carry out (1 point)
Has overflow (1 point)
6.


(8 points)
7.
a) (7 points)
Input/Output Signal R-format lw sw beq
Op5 0 1 1 0
Op4 0 0 0 0
Op3 0 0 1 0
Inputs Op2 0 0 0 1
Op1 0 1 1 0
Op0 0 1 1 0
RegDst 1 0 X X
RegWrite 1 1 0 0
MemRead 0 1 0 0
Outputs MemWrite 0 0 1 0
MemtoReg 0 1 X X
Branch 0 0 0 1
ALUSrc 0 1 1 0
ALUOp1 1 0 0 0
ALUOp0 0 0 0 1

b)
(5 points)
Inputs
Op5 Op4 Op3 Op2 Op1 Op0 AND plane

Outputs
RegDst RegWrite MemRead MemWrite MemtoReg Branch ALUSrc ALUOp1 ALUOp0
8.
a) 4 (1 point)
b) 10 (1 point)
c) 22 (1 point)
d) 0-1023 (1 point)
e) 48d1 (2 points)
f) 16K (1 point)
9.

Set Index Tag Tag
0 8 4
1 2 8
2
3
4
5
6
7

(1 point for set indices) (1 point each for other entries)
10.
(-1)1 x 1.0two x 2128 + 2 + 1 C 127
1st number: = -1.0two x 24 (1 point)
(-1)0