# CS501 Advance Computer Architecture Assignment 1 Solution Fall 2014

 Question No. 1                                                                                                                 10 Marks

Write assembly language instructions to execute the following expression on 0-address and 3-address machines.

F = A + (B × C / D) – E

 Question No. 2                                                                                                                  10 Marks

A compiler designer is trying to decide between two code sequences for a particular machine. The hardware designers have supplied the following facts:

 Instruction Class CPI required for each class A 2 B 3 C 2

The compiler designer intends to write two code sequences to achieve a task. Both code sequences are required the following instruction count.

 Code Sequence Instruction Count for each sequence A B C 1 10 5 8 2 6 4 9

a)      Which code sequence will execute faster? Justify your answer on the basis of CPU clock cycles calculations.

b)     What is the CPI for each code sequence?

### Question # 1:

F = A + (B × C / D) – E

push B

push C

mul

push D

div

push A

Push E

sub

pop F

mul F,B,C

div F,F,D

Sub F,F,E

### (a):

Question 2 (b)

CPI = clock cycle for each type of instruction / IC

Code Sequence 1

Clock cycle for each type of instruction = 51

Instruction count (IC) = 10+5+8 =23

CPI= 51/23

= 2.217

Code Sequence 2

Clock cycle for each type of instruction = 42

Instruction count (IC) = 6+4+9  =19

CPI= 42/19

= 2.210