=========================preview======================
(ELEC152)[2010](s)midterm~=dgqrr^_31178.pdf
Back to ELEC152 Login to download
======================================================
Department of Electronic and Computer Engineering The Hong Kong University of Science and Technology
ELEC152 Sample Midterm Exam
Name:
Student Number
Time: 90 min closed book examination
Answer all Questions in this examination in the space provided
Return the paper with your Name and student No. in the classroom
MIPS reference card is on the last pages!
Question 1 5
Question 2 5
Question 3 10
Question 4 10
Question 5 10
Question 6 10
Question 7 15
Question 8 35
Total 100
Question 1: (5 points)
Suppose the 32-bit number 0x12345678 is stored at address 0x100 in little endian format.
What are the values of memory locations 0x100, 0x101, 0x102, 0x103?
Answer: 0x100=__0x78____ 0x101=__0x56___
0x102=__0x34___ 0x103=__0x12___
Question 2: (5 points)
For an 8-bit unsigned number, what is the value range? For an 8-bit 2s complement number,
what is the range of value it can represent?
Answer: a. 0 to 255
b. -128 to 127
Question 3: (10 points) Imagine you read a word from the memory. 0000000100001001,1000000000100000 Please consider the following questions. a) If this word represents an integer in 2s compliment, what would be the decimal value? What would be the hexdecimal value? b) If this word represents a MIPS instruction, from the instruction table in the appendix, which instruction is it?
Answer: a. 224+219+216+215+25=1739984010
0000,0001,0000,1001,1000,0000,0010,0000=0x01098020
b. 000000,01000,01001,10000,00000,100000
rs=8, rt=9, rd=16, func=32
add $s0, $t0, $t1
Question 4: (10 points)
For MIPS, what is the value range for integers in 2s compliment? If we assume that single-precision floating point number is represented with the formula in the appendix, what is the
value range for single-precision floating point number?
Answer: a. -231 , 231-1
b. underflow: E=0, significant=1.0, 12-127 overflow: E=28-1=255, significant=1.111(23 1s), (1+2-1+2-2+2-
.24
1. 2 2128
23)2128
=
1. 2.1
Question 5: (10 points)
For the following MIPS assembly segments, please calculate for the required results
0x100 addi $s0, $zero, 4000
0x104 lw $t0, 100($s0) #what is the mem. address for the target
#word?
0x108 beq $t0, $t1, L1 #what is the offset for L1 in the machine
#instruction?
0x10c addi $s0, $s0, 4
0x110 j L2 #what is the offset for L2 in the machine
#instruction?
0x114 L1: addi $s0, $s0, 3
0x118 addi $s0, $s0, 2
0x11c L2: addi $s0, $s0, 1
Answer: a. 4100
b.
2
c.
L2=0001,0001,1100, offset=00,0100,0111=7110
Question 6: (10 points)
Consider program P, which runs on a 1GHz machine M in 10 seconds. An optimization is made to P, replacing all instances of multiplying a value by 4 (mult X, X, 4) with two instructions that set x to x+x twice (add x,x,x; add x,x,x). Call this new optimized program p. The CPI of a multiply instruction is 4, and the CPI