Professional Documents
Culture Documents
Midterm 1 Sol.pdf
Midterm 1 Sol.pdf
Name _________________________________________________________
Email _________________________________________________________
One hour total; equal points per problem; 25% of your grade.
Solution checking
1 Yajie Yen-Yi
2 Tee Yajie
3 Jordan Tee
4 Paul Jordan
5 Yen-Yi Jordan
6 Jordan Paul
7 Jordan Zhizhen
8 Zhizhen Jordan
1. Computer A uses one ISA and has a 2 GHz clock frequency. Computer B uses a different
ISA and has a 3 GHz clock frequency. On average, A's programs execute 1.5 times as many
instructions as B's. For program P1, computer A has a CPI of 2 and computer B has a CPI of 3.
Which computer has faster execution time? What is the speedup?
A 2 GHz 2 1.5×
B 3 GHz 3 1×
IC B × CP I B
P erf ormance A Execution T imeB Clock RateB Clock RateA IC B CP I B 2 1 3 2
P erf ormanceB
= Execution T imeA
= IC A ×CP I A = Clock RateB
× IC A
× CP I A
= 3
× 1.5
× 2
= 3
Clock RateA
load 30% 4
store 10% 4
add 50% 2
multiply 8% 16
divide 2% 50
If you could pick one type of instruction to make twice as fast (half the latency) in the
next-generation of this processor, which instruction type would you pick? Why?
A. l oad _____
B. store _____
C. add _____
D. multiply _____
E. divide _____
Assuming that total number of instructions is 100: 30 load, 10 store, 50 add, 8 multiply, 2 divide
(30*4)+(10*4)+(50*2)+(8*16)+(2*50)
C P I base = 30+10+50+8+2 = 4.88
(30*2)+(10*4)+(50*2)+(8*16)+(2*50)
C P I load = 30+10+50+8+2 = 4.28
(30*4)+(10*2)+(50*2)+(8*16)+(2*50)
C P I store = 30+10+50+8+2 = 4.68
(30*4)+(10*4)+(50*2)+(8*8)+(2*50)
C P I mults = 30+10+50+8+2 = 4.28
(30*4)+(10*4)+(50*2)+(8*16)+(2*25)
C P I divs = 30+10+50+8+2 = 4.38
A. 1.0X _____
B. 1.20X _____
C. 1.25X _____
D. 1.5X _____
E. 1.6X _____
F. 2.0X _____
Solution
if (a > b)
{
do
{
a = a - b;
} while (a >= 55);
--b;
}
else
{
b = b + 44;
}
Solution
/* assume a is in r0 and b is in r1 */
CMP r0, r1
loop:
else:
done:
5. What does each line of the following ARM assembly code (Euclid's Greatest Common Divisor
algorithm) do?
while(a != b) {
if(a>b) a -= b;
else b -= a;
}
6. Represent each value in as many ways as possible as an ARM immediate:
0x600
Rotate Immediate
0xC 0x06
0xD 0x18
0xE 0x60
0xC0
Rotate Immediate
0x0 0xC0
0xF 0x30
0xE 0x0C
0xD 0x03
0x102
Impossible
7. For each assembly code snippet, list the values of the controls listed. Use a single X for don't
care. Note the width of each signal and be sure you enter a digit for each wire in the signal
(e.g. for signal[2:0] write 001 instead of just 1).
instruction add r3, r1, r3 mvn r3, #8 str r3, [r2, #4] ldr r6, [r3, #0]
mem_to_reg 0 0 X 1
reg_write_en[0] 1 1 0 1
immed_alu[0] 0 1 1 1
alu_op[3:0] 4 F 4 4
mem_write_en[0] 0 0 1 0
Explanation: -0x40=-0100_0000=1100_0000