You are on page 1of 34

Systems Programming

Tutorial Three: Sheet One Solution

Lecture Instructor : Prof. Dr. Ahmed El Nahas


Tutorial Instructor: Eng. Ahmed Abdelhamid Waheed Abdelwahab

1
Exercises(1)
1. Give assembly language instruction for each of the following actions.
a) Declare an integer array named P1 of 50 elements.
b) Define character string P2 whose value is ‘Alex. Uni.’
c) Define an integer P3 whose value is 100.
d) Increase the value of the accumulator by the contents of the object whose address is stored in
P4.
e) Multiply the contents of register T by the contents of register S.
f) Decrease the current value of the location counter by 10.
g) Define a name P5 with value: 10 bytes after location P6.
h) Increase the value of index register by 1, and compare the result with value stored in P7.
i) Assign the value 1000 to the location counter.
j) Declare a character array of named P8 of 50 elements.
k) Define a hexadecimal constant P9 of ‘69AB’.
l) Test device defined by P10.
m) Read character from device defined by P11.
n) Write character to device defined by P12.

2
Solution
No. Label Mnemonic Operand
a) P1 RESW 50
b) P2 BYTE C’Alex. Uni.’
c) P3 WORD 100
d) ADD @P4
e) MULR S,T
f) ORG *-10
g) P5 EQU P6+10
h) TIX P7
i) ORG 1000
j) RESB 50
k) P9 BYTE X’69AB’
3
Solution(CONT’D)
No. Label Mnemonic Operand
l) TD P10
m) RD P11
n) WD P12

4
Exercises(2)
2. Write a SIC/XE assembly language code snippets for each of the
following pseudo code snippets:

5
Exercises(2)(a)
a. p:= 4 ; q:= 3;
If p*q>10 then {p:=1 ; q:=2*p;}
else {p:=100;q:=200;}
res := p+q;

6
Solution
Label Mnemonic Operand
LDA #4
STA P
LDA #3
STA Q
LDA P
MUL Q
COMP #10
JGT THEN
LDA #100
STA P
LDA #200
STA Q 7
Solution(CONT’D)
Label Mnemonic Operand
J OUT
THEN LDA #1
STA P
LDA #2
MUL P
STA Q
OUT LDA P
ADD Q
STA RES
P RESW 1
Q RESW 1
RES RESW 1 8
Solution(Complete Program)
Label Mnemonic Operand
PROG START 0
LDA #4
STA P
LDA #3
STA Q
LDA P
MUL Q
COMP #10
JGT THEN
LDA #100
STA P
LDA #200
STA Q 9
Solution(CONT’D)
Label Mnemonic Operand
J OUT
THEN LDA #1
STA P
LDA #2
MUL P
STA Q
OUT LDA P
ADD Q
STA RES
P RESW 1
Q RESW 1
RES RESW 1
END 10
Exercises(2)(b)
b. Y:=8;
if Y=0 then Q:=16
else Q:=1;
Z:= Q;

11
Solution
Label Mnemonic Operand
LDA #8
STA Y
LDA Y
COMP #0
JEQ THEN
LDA #1
STA Q
J OUT
THEN LDA #16
STA Q
OUT LDA Q
STA Z 12
Solution(CONT’D)
Label Mnemonic Operand
Y RESW 1
Q RESW 1
Z RESW 1

13
Solution(Complete Program)
Label Mnemonic Operand
PROG START 0
LDA #8
STA Y
LDA Y
COMP #0
JEQ THEN
LDA #1
STA Q
J OUT
THEN LDA #16
STA Q
OUT LDA Q
STA Z 14
Solution(CONT’D)
Label Mnemonic Operand
Y RESW 1
Q RESW 1
Z RESW 1
END

15
Exercises(2)(c)
c. If Y+7 ≤ Z
then begin E:=10Z3-3Z+6; Z:=Z+1; end
else begin E:= 5(Y-Z); Z:=Z-1; end

16
Solution
You can use mathematical manipulations for this like:
Z(10Z2-3)+6 for the first expression of E
or using general purpose registers to store intermediate values. I will go
for the first approach but you are free to go for anyone.

17
Solution(CONT’D)
Label Mnemonic Operand
LDA Y
ADD #7
COMP Z
JGT ELSE
LDA #10
MUL Z
MUL Z
SUB 3
MUL Z
ADD #6
STA E
18
Solution(CONT’D)
Label Mnemonic Operand
LDA Z
ADD #1
STA Z
J OUT
ELSE LDA Y
SUB Z
MUL #5
STA E
LDA Z
SUB #1
STA Z
19
Solution(CONT’D)
Label Mnemonic Operand
OUT ….. …..
Y RESW 1
Z RESW 1
E RESW 1

20
Solution(Complete Program)
Label Mnemonic Operand
PROG START 0
LDA Y
ADD #7
COMP Z
JGT ELSE
LDA #10
MUL Z
MUL Z
SUB 3
MUL Z
ADD #6
STA E 21
Solution(CONT’D)
Label Mnemonic Operand
LDA Z
ADD #1
STA Z
J OUT
ELSE LDA Y
SUB Z
MUL #5
STA E
LDA Z
SUB #1
STA Z
22
Solution(CONT’D)
Label Mnemonic Operand
OUT ….. …..
Y RESW 1
Z RESW 1
E RESW 1
END

23
Exercises(2)(d)
d. If Y+3 ≤ Z
then begin R := 10*Z+20; Z := Z+1; end
else begin R := 5*(Y-Z); Z := Z-1; end
Y := R + Z

24
Solution
Label Mnemonic Operand
PROG START 0
LDA Y
ADD #3
COMP Z
JGT ELSE
LDA #10
MUL Z
ADD #20
STA R
LDA Z
ADD #1
STA Z
J OUT 25
Solution(CONT’D)
Label Mnemonic Operand
ELSE LDA Y
SUB Z
MUL #5
STA R
LDA Z
SUB #1
STA Z
OUT LDA R
ADD Z
STA Y

26
Solution(CONT’D)
Label Mnemonic Operand
Y RESW 1
Z RESW 1
R RESW 1
END

27
Exercises(2)(e)
e. Z := 15;
If Y+3 ≤ Z
then begin R := 10*Z+20; Z := Y+1; end
else begin R := (Z - Y) ÷ R; Z := Z-1; end
Y := 5*R + Z;

28
Solution
Label Mnemonic Operand
LDA #15
STA Z
LDA Y
ADD #3
COMP Z
JGT ELSE
LDA #10
MUL Z
ADD #20
STA R
LDA Y
ADD #1 29
Solution(CONT’D)
Label Mnemonic Operand
STA Z
J OUT
ELSE LDA Z
SUB Y
DIV R
STA R
LDA Z
SUB #1
STA Z
OUT LDA #5
MUL R
ADD Z
30
STA Y
Solution(CONT’D)
Label Mnemonic Operand
Y RESW 1
Z RESW 1
R RESW 1

31
Solution(Complete Program)
Label Mnemonic Operand
PROG START 0
LDA #15
STA Z
LDA Y
ADD #3
COMP Z
JGT ELSE
LDA #10
MUL Z
ADD #20
STA R
LDA Y
ADD #1 32
Solution(CONT’D)
Label Mnemonic Operand
STA Z
J OUT
ELSE LDA Z
SUB Y
DIV R
STA R
LDA Z
SUB #1
STA Z
OUT LDA #5
MUL R
ADD Z
33
STA Y
Solution(CONT’D)
Label Mnemonic Operand
Y RESW 1
Z RESW 1
R RESW 1
END

34

You might also like