Instructor:
Assoc. Prof. Dr. Alexander CHEFRANOV
Time: 50 minutes
MOBILES ARE NOT ALLOWED!!!
YOU CAN BRING ONE A4 SIZED SHEET OF HAND-WRITTEN NOTES TO THE
EXAM. PHOTOCOPIES ARE NOT ALLOWED AND WILL BE COLLECTED.
READ THE INSTRUCTIONS FOR EACH SECTION CAREFULLY.
PART I
PART II
Grading
TOTAL
1
A. (25 points) Consider 0-address machine instruction set below:
where the processor has a stack and some supporting hardware, at least a top of stack
(TOS) pointer.
Operation e.g. or comment load_literal <int> effect:
TOS:=TOS+1; stack[TOS]:=<int> load a constant onto the top of stack; this can be used in arithmetic or to get an address onto the stack for use by a load or a store instruction later (it is splitting hairs to argue whether the literal is an address or a constant which might happen to be used as an address elsewhere) load sto effect: stack[TOS]:=memory[stack[TOS]] take the top-of-stack as an address, replace the top-of-stack with the contents of that address. effect: memory[stack[TOS-1]]:=stack[TOS]; TOS:=TOS-2 store contents of top of stack at the address in stack[TOS-1] then pop the value and the address
<opcd> where <opcd> is add | sub |... effect: stack[TOS-1] := stack[TOS-1] <op> stack[TOS];
TOS:=TOS-1
For the expression
X=(y-z)/z+w
1.
Give the reverse Polish notation (5 points)
Xyz-z/w+=
2.
Write the 0-address machine code to implement it (10 points)
1.
Load_literal @x
2.
Load_literal @y
3.
Load
4.
Load_literal @z
5.
load
6.
Sub
7.
Load_literal @z
8.
Load
9.
div
2
10.
Load_literal @w
11.
Load
12.
Add
13.
sto
3.
Trace the code assuming x=3, y=2, z=1, w=2: show state of the memory cells allocated for the variables and state of the stack initially and after each instruction completion. (10 points)
After X= 3
Instruction
# addr=100
Y=2 addr=101
Z=1 addr=102
W=2 addr=103
Stack
1
2
100
100,101
3
4
5
6
100,2
100,2,102
100,2,1
100,1
7
8
9
10
11
12
13 3
100,1,102
100,1,1
100,1
100,1,103
100,1,2
100,3
3
B. (25 points) Consider two Boolean functions, z0 and z1, presented in the truth table below x
2 x
1 x
0 z
1 z
0
0 0 0 0 1
0 0 1 1 0
0 1 0 0 1
0 1 1 1 1
1 0 0 1 0
1 0 1 0 1
1 1 0 0 1
1 1 1 1 0
Give a PLA implementation for z0 and z1. z z
0
1
x
2 x
1 x
0 x
2 x
1 x
0
x
2 x
1 x
0
x
2 x
1 x
0
x
2 x
1 x
0 x
2 x
1 x
0
x
2 x
1 x
0 x
2 x
1 x
0
x
2 x
1 x
0
4
A. (20 points) Calculate processor utilization and hyperperiod for the following task set:
Task# E P
1
2
3
3
6
4
10
11
7
U
3
10
6
11
4
7
231
420
440
770
1091
770
H=10*11*7=770
B.
(15 points) Consider priority preemptive system with 3 tasks – t1, t2, t3, having execution times 50, 30, 60 and priorities – 3,1,2 respectively (priority of level 1 is highest). They arrive at time instances 2,3,5 respectively. What is the time to complete task 1,2,3? Illustrate your answer by a time diagram.
Task t1 starts at moment 2 and is preempted at moment 3 by higher priority task t2, which develops 30 time units and completes at time 32. Task t2 time to complete is 30.
Task t2 is not preempted by coming at time 5 task t3 as far as t3 has lower priority than that of t2. At time 33, there are two tasks in the system: t1 and t3, t3 having higher priority. It is assigned, develops for 60 time units, and completes at moment 93, hence its time to complete is 93-5=88. Task t1 resumes at moment 93 and takes 49 time to complete at time moment 142, hence task t1 time to complete is 142-2=140.
C.
(15 points) Construct a cyclic executive with four procedures, A,B,C, and D.
Procedure A runs three times as frequently as B and C, and procedure C runs two times as frequently as D .
For(;;){ For(i=1,6)A;
B;B;C;C;D;
}
5