You are on page 1of 16

Systems Programming

Tutorial Eight: Sheet Three Solution

Lecture Instructor : Prof. Dr. Ahmed El Nahas


Tutorial Instructor: Eng. Ahmed Abdelhamid Waheed Abdelwahab

1
Exercises(1)
1. a) Write a SIC/XE assembly language definition of the function
FUN(U, Q, R), that stores in U the value: 5Q3 + R.
b) Write coding of the call: FUN(UU, QQ, RR).

2
Solution-Subroutine

Label Mnemonic Operand


FUN LDA #5
MUL Q
MUL Q
MUL Q
ADD R
STA @U
RSUB
U RESW 1
Q RESW 1
R RESW 1

3
Solution-Call

Label Mnemonic Operand


LDA #UU
STA U
LDA QQ
STA Q
LDA RR
STA R
JSUB FUN
UU RESW 1
QQ RESW 1
RR RESW 1

4
Exercises(2)
2. a) Write definition of subroutine fun(P, Q, R), that returns in R the
value:
𝑃 + 10 𝑄 + 20 𝑖𝑓 𝑃 ≤ 𝑄
R=൝
𝑄 2 + 15 𝑖𝑓 𝑃 > 𝑄
b) Write code for the call: fun(AP, AQ, AR)

5
Solution-Subroutine
Label Mnemonic Operand
FUN LDA P
COMP Q
JGT ELSE
LDA P
ADD #10
MUL Q
ADD #20
STA @R
J DONE
ELSE LDA Q
MUL Q
ADD #15 6
Solution-Subroutine
Label Mnemonic Operand
STA @R
DONE RSUB
P RESW 1
Q RESW 1
R RESW 1

7
Solution-Call
Label Mnemonic Operand
LDA AP
STA P
LDA AQ
STA Q
LDA #AR
STA R
JSUB FUN
AP RESW 1
AQ RESW 1
AR RESW 1

8
Exercises(3)
3. Write a sequence of assembly instructions equivalent to the
function func, having two parameters n, R:
void func(int n, int &R)
{𝑅 = 10 ∗ 𝑛 ∗ 𝑛 − 5;}

9
Solution

Label Mnemonic Operand


FUNC LDA #10
MUL N
MUL N
SUB #5
STA @R
RSUB
N RESW 1
R RESW 1

10
Exercises(4)
4. a) Write a SIC/XE assembly language definition of function
FUN(Q, P), that returns in P the value:
𝑃= 10𝑄 + 20 𝑄 + 30 𝑄 + 40
b) Write code for the call: FUN(AQ, AP).

11
Solution-Subroutine

Label Mnemonic Operand


Fun LDA #10
MUL Q
ADD #20
MUL Q
ADD #30
MUL Q
ADD #40
STA @P
RSUB
Q RESW 1
P RESW 1
12
Solution-Call

Label Mnemonic Operand


LDA AQ
STA Q
LDA #AP
STA P
JSUB FUN
AQ RESW 1
AP RESW 1

13
Exercises(5)
5. a) Write a SIC/XE assembly language definition of function:
void func(int * p1, int * P2, int c) {
*p1 = *p1 + c;
*p2 = *p2 – c;
}
b)Write code for the call: func(pa1, pa2, <your_college_id>);.

Let it be 9000 for example

14
Solution-Subroutine

Label Mnemonic Operand


FUNC LDA @P1
ADD C
STA @P1
LDA @P2
SUB C
STA @P2
RSUB
P1 RESW 1
P2 RESW 1
C RESW 1

15
Solution-Call

Label Mnemonic Operand


LDA #PA1
STA P1
LDA #PA2
STA P2
LDA #9000
STA C
JSUB FUNC
PA1 RESW 1
PA2 RESW 1

16

You might also like