Professional Documents
Culture Documents
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
3
Solution-Call
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
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
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>);.
14
Solution-Subroutine
15
Solution-Call
16