You are on page 1of 4

Question 1

Given the function X = (A B + C - D) E


a)

Write the program to compute the function using the address instruction types below. Do
not modify the values of A, B, C, D and E. You may use X or any temporary location T to
store intermediate results.
i.

3 address instructions

ii.

SUB A, B, X
SUB C, D, T
ADD X, T, X
MULT X, E, X
2 address instructions

(1 mark)

(1 mark)
LOAD A, X
SUB B, X
ADD C, X
SUB D, X
MULT E, X

iii.

1 address instruction
(1 mark)
LOAD
SUB
ADD
SUB
MULT
STORE

b)

A
B
C
D
E
X

Given the time to fetch, decode and execute each instruction as follows:
Instruction type
3 address instruction
2 address instruction
1 address instruction

Time per instruction


100ns
70ns
50ns

Calculate the time to compute the above function for each addressing instructions.
(3 marks)
Ans:
100ns x 4 = 400ns (3 address instruction)
70ns x 5 = 350ns(2 address instruction)
50ns x 6 = 300ns(1 address instruction)

c)

Compute the memory traffic for each addressing instructions.


(Assume opcode = 1 byte, address and data = 2 bytes)

(3 marks)
3 address instruction
(3 marks)
Instruction
SUB A, B, X
SUB C, D, T
ADD X, T, X
MULT X, E, X

Instruction fetch
7
7
7
7

Data traffic
6
6
6
6

Total
13
13
13
13

28

24

52 bytes

Instruction fetch

Data traffic

Total

5
5
5
5
5

4
6
6
6
6

9
11
11
11
11

25

28

53 bytes

Instruction fetch
3
3
3
3
3
3

Data traffic
2
2
2
2
2
2

Total
5
5
5
5
5
5

18

12

30 bytes

2 address instruction
Instruction
LOAD A, X
SUB B, X
ADD C, X
SUB D, X
MULT E, X

1 address instruction
Instruction
LOAD A
SUB B
ADD C
SUB D
MULT E
STORE X

Question 2
Below is an ARC assembly program to compute X which is a function of A, B and D.
.begin
.org 1200
ld [C],%r1
ld [A], %r2
ld [B], %r3
ld [D], %r4
label1: orncc %r2, %r2, %r5
orncc %r3, %r2, %r6
orncc %r4, %r5, %r7
andcc %r4, %r3, %r8
orncc %r6, %r7, %r9
orcc %r6, %r8, %r10
st %r10, [X]
addcc %r1, -1, %r1
be label2
ba label1
label2: halt
A:
2
B:
3
C:
4
D:
1
X:
0
.end
HexLoc

DecLoc MachWord Label


Instruction
Comment
.org 1200
000004b0 0000001200 c20024f4
ld [1268], %r1
000004b4 0000001204 c40024ec
ld [1260], %r2
000004b8 0000001208 c60024f0
ld [1264], %r3
000004bc 0000001212 c80024f8
ld [1272], %r4
000004c0 0000001216 8ab08002 label1:
orncc %r2, %r2, %r5
000004c4 0000001220 8cb0c002
orncc %r3, %r2, %r6
000004c8 0000001224 8eb10005
orncc %r4, %r5, %r7
000004cc 0000001228 90890003
andcc %r4, %r3, %r8
000004d0 0000001232 92b18007
orncc %r6, %r7, %r9
000004d4 0000001236 94918008
orcc %r6, %r8, %r10
000004d8 0000001240 d42024fc
st %r10, [1276]
000004dc 0000001244 82807fff
addcc %r1, -1, %r1
000004e0 0000001248 02800002
be 2
000004e4 0000001252 10bffff7
ba -9
000004e8 0000001256 ffffffff
label2:
halt
000004ec 0000001260 00000002 A:
000004f0 0000001264 00000003 B:
000004f4 0000001268 00000004 C:
000004f8 0000001272 00000001 D:
000004fc 0000001276 00000000 X:

a) Write the machine code for the following instructions:


(Refer to ARC Instruction formats on page 9)
ld [C],%r1

i.

c20024f4

ii. andcc %r4, %r3, %r8


90890003

iii. orncc %r3, %r2, %r6


8cb0c002

iv. be label2
02800002

v. ba label1
10bffff7

vi. st %r10, [X]


d42024fc

(18 marks)

c) Generate a symbol table for the program.


Symbol
Label1
Label2
A
B
C

Address
1216
1256
1260
1264
1268

1272

1276

(4 marks)

You might also like