Sunday, October 30, 2011

cs501 assignment no 1 solution fall 2011

Assignment No. 01
Semester Fall 2011
Advance Computer Architecture - CS501

Total Marks: 20

Due Date: 31/10/2011

Objective:
To learn and understand classification of instructions.

Instructions:
Please read the following instructions carefully before solving & submitting assignment:
Assignment should be in your own wordings not copied from net, handouts or books.
It should be clear that your assignment will not get any credit (zero marks) if:

o        The assignment is submitted after due date.
o        The submitted assignment does not open or file is corrupt.
o        The assignment is copied (from other student or copied from handouts or internet).



GOOD LUCK
Question No 1

Marks: 5+5+5+5 = 20 

Write the code to implement the expression A = (B+C) * (D + E) for

1)      3-address instructions
2)      2-address instructions
3)      1-address instructions
4)      0-address instructions

In accordance with programming language practice, computing the expression should not change the values of its operands.

=========================================================================

Solution

1)      3-address instructions

add x, b, c
add y, d, e
mul a, x, y

2)      2-address instructions


 load r, d                                                   
add r, e
 load y, b       
add y, c                                           
 mul y, r                                                   
store a, y

3)      1-address instructions

lda B
adda C
sta x
lda D
adda E
mula x
sta A



4)      0-address instructions

push b                                                   
push c
add
push d                                                   
push e          
add
mul                                                   
pop a




No comments:

Post a Comment