CompArch Sample Exam With Answers
CompArch Sample Exam With Answers
PART II
Write answers briefly for the following questions
5. (6 pts )Explain what happens during Instruction Fetch and Interrupt Cycle With simple steps.
Answer:
Instruction Fetch
PC contains address of next instruction
Address moved to MAR
Address placed on address bus
Control unit requests memory read
Result placed on data bus, copied to MBR, then to IR
Meanwhile PC incremented by 1
Interrupt Cycle
PART III
Show all the Necessary steps for the Questions below.
7. (4 pts.) Write programs to compute for each of the four machines and compare one-, two-
, and three-address machines by writing programs to compute for each of the four
machines.
X = (A – B/ C) / (D* E + F)
Answer:
3-address 2-address
Comment Comment
DIV Z,B,C Z<=B/C LOAD Z,B Z<=B
SUB Z,A,Z Z<=A-Z DIV Z,C Z<=Z/C
MULT K,D,E K<=D*E LOAD X,A X<=A
ADD K,F,K Z<=F+K SUB X,Z X<=X-Z
DIV X,Z,K X<=Z/K LOAD Z,D Z<=D
MULT Z,E Z<=Z*E
ADD Z,F Z<=Z+F
DIV X,Z X<=X/Z
To calculate the index, we need to use the information given regarding the total capacity of
the cache:
- 2 MB is equal to 223 total bytes.
- We can use this information to determine the total number of blocks in the
cache…
o 223 bytes x (1 block / 32 words) x (1 word / 32 bits) x (8 bits / 1 byte) = 2 16 blocks
- Now, there are 4 (or 212) blocks / set
o Therefore there are 216 blocks x (1 set / 21 blocks) = 215 sets
- Thus, 15 bits of index are needed
Finally, the remaining bits form the tag:
- 32– 6 – 15 = 11
- Thus, there are 11 bits of tag
9. (6 pts.) Assume that the following sequence of instruction is executed by the processor with a
pipeline containing stages: IF, ID, EX, M and W; and contains a single memory for read/write.
I1: Load R1,M(25)
I2: Mul R2,R3
I3: Sub R1,R2
I4: Add R2, R3
I5: Stor R2,M(45)
Using the table below, show the instruction that resides in each stage of the pipeline for each clock period.
Instructions Clock cycle number
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Load R1,M(25) IF ID Ex M W
Mul R2,R3 IF ID Ex M W
Sub R1,R2 IF ID # # Ex M W
Add R2, R3 IF # # ID Ex M W
Stor R2,M(45) IF ID Ex # M W