0% found this document useful (0 votes)
145 views45 pages

SP HW Merged

system programming homeworks

Uploaded by

sara
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
145 views45 pages

SP HW Merged

system programming homeworks

Uploaded by

sara
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 45

PALESTINE POLYTECHNIC UNIVERSITY

COLLEGE OF INFORMATION TECHNOLOGY AND COMPUTER ENGINEERING


SYSTEMS PROGRAMMING
INSTRUCTOR: ENG. YOUSEF SALAH
HOMEWORK #1 –SPRING2020
DEADLINE: WEDNESDAY 19/02/2020

Q1) For the following SIC Program, answer the questions that follow:

a) Draw the symbol table SYMTAB.


b) Generate the listing file.
c) Generate the object program file.
d) What is the program size?

Q2)
Q3)
PALESTINE POLYTECHNIC UNIVERSITY
COLLEGE OF INFORMATION TECHNOLOGY AND COMPUTER ENGINEERING
SYSTEMS PROGRAMMING
INSTRUCTOR: ENG. YOUSEF SALAH
HOMEWORK #2 –SPRING2020
DEADLINE: WEDNESDAY 26/02/2020

Write a Python program that reads as an input a SIC source code having the
following fixed format nature:

1-8 Label
9-9 Blank
10-15 Operation code (or Assembler directive)
16-17 Blank
18-35 Operand
36-66 Comment
A line that starts by a period (.) is a comment.

Your program should generate the followings as an output:


1- What is the name of the program?
2- Separate each column as a list.
3- How many lines are comments?
4- How many directives in the source code?
5- How many instructions in the source code?
6- Which lines contain indexed addressing?
"""
Name:Latifa Masri
161040:#
HW#2
"""
initilization needed variables and list#
'' = PROGRNAM
][ = labelList
][ = operationCodeList
][ = operandList
][= commentList
countCommentLine = 0
countDirective = 0
countInstruction = 0
][ = indexingAddressingLines
directive = ['START','END','BYTE','WORD','RESB','RESW','BASE','NOBASE']
fh = open('./InputFile.txt','r')#open file just for read
)(f=fh.readlines
PROGRNAM= f[0][0:8] #store the name of the program
print("the program name is : "+ PROGRNAM)
:for line in f
:'.' == ]0:1[if line
countCommentLine+=1
:else
countInstruction+=1
)(label = line[0:8].strip
)(op = line[9:15].strip
)(operand = line[17:35].strip
)(comment = line[35:66].strip

labelList.append(label)
operationCodeList.append(op)
operandList.append(operand)
commentList.append(comment)

:if op in directive
countDirective+=1

:if ',X' in operand


indexingAddressingLines.append("line#" +
str(countInstruction + countCommentLine))
)(fh.close
print("labels :" + str(labelList))
print("operation code: "+ str(operationCodeList))
print("operand: "+ str(operandList))
print("comments: "+ str(commentList))
print("the number of directive is: "+ str(countDirective) )
print("the number of instruction is: "+ str(countInstruction -
countDirective))
print("indexing addressing line is : "+ str(indexingAddressingLines))
print("the number of comment line is : "+ str(countCommentLine))
PALESTINE POLYTECHNIC UNIVERSITY
COLLEGE OF INFORMATION TECHNOLOGY AND COMPUTER ENGINEERING
SYSTEMS PROGRAMMING
INSTRUCTOR: ENG. YOUSEF SALAH
HOMEWORK #3 –SPRING2020
DEADLINE: WEDNESDAY 04/03/2020

Q1) For the following SIC/XE Program, answer the questions that follow:

a) Draw the symbol table SYMTAB.


b) Generate the object program file (considering it as a relocatable program).
c) What is the program size?

Q2) Write the SIC/XE assembler logic for each of PASS1 and PASS2.
Q3)

Q4)

Q5)
Scanned by TapScanner
Scanned by TapScanner
Scanned by TapScanner
Scanned by TapScanner
Scanned by TapScanner
Scanned by TapScanner
Scanned by TapScanner
Scanned by TapScanner
Scanned by TapScanner
Scanned by TapScanner
Scanned by TapScanner
PALESTINE POLYTECHNIC UNIVERSITY
COLLEGE OF INFORMATION TECHNOLOGY AND COMPUTER ENGINEERING
SYSTEMS PROGRAMMING - SPRING2020
HOMEWORK #4
INSTRUCTOR: ENG. YOUSEF A. SALAH

Q1) Consider the following SIC program and answer the questions that follow:

1 EMPR START 200


2 ALPHA RESW 256
3 ABC LDA XYZ
4 STA LMN
5 LDX PQR
6 XYZ WORD -1
7 LMN BYTE X’CDAFEB’
8 PQR RESB C’PPU’
9 HIJ RESB 32
10 LDA HIJ
11 LDX XYZ
12 END ABC

A) Using a load-and-go ONE PASS assembler, draw the shape of the SYMTAB at
each line.
B) Using a ONE PASS assembler that generates an object file for later execution, find
out the generated object file.

Q2)
Q3)

Q4)

Q5) How would you design the SYMTAB of the ONE PASS load-and-go
Assembler as a data structure in C++?
Name: Latifa Masri
161040
Home work #4

Q1) Consider the following SIC program and answer the questions that follow:
0200 EMPR START 200 opcode
0200 ALPHA RESW 256
0500 ABC LDA XYZ 000509
0503 STA LMN 0C0509
0506 LDX PQR 04050F
0509 XYZ WORD -1 FFFFFF
050C LMN BYTE X’CDAFEB’ CDAFEB
050F PQR BYTE C’PPU’ 505055
0512 HIJ RESB 32
0532 LDA HIJ 000512
0535 LDX XYZ 040509
0538 END ABC

A) Using a load-and-go ONE PASS assembler, draw the shape of the SYMTAB at
each line.

1) 0200 EMPR START 200 2) 0200 ALPHA RESW 256


SYMTAB: EMPR 0200
EMPR 0200
ALPHA 0200

3) 0500 ABC LDA XYZ 4) 0503 STA LMN

EMPR 0200
EMPR 0200
ALPHA 0200
ALPHA 0200
ABC 0500
ABC 0500
XYZ * 0501 0501
XYZ *
LMN *
0504

5) 0506 LDX PQR


EMPR 0200
ALPHA 0200
ABC 0500
0501
XYZ *
LMN *
0504
PQR *
0507
6) 0509 XYZ WORD -1
EMPR 0200
ALPHA 0200
ABC 0500
XYZ 0509
LMN * 0504
PQR *
0507

7) 050C LMN BYTE X’CDAFEB’

EMPR 0200
ALPHA 0200
ABC 0500
XYZ 0509
LMN 050C
PQR * 0507

8) 050F PQR BYTE C’PPU’


EMPR 0200
ALPHA 0200
ABC 0500
XYZ 0509
LMN 050C
PQR 050F

9) 0512 HIJ RESB 32


EMPR 0200
ALPHA 0200
ABC 0500
XYZ 0509
LMN 050C
PQR 050F
HIJ 0512

10) 0532 LDA HIJ

EMPR 0200
ALPHA 0200
ABC 0500
XYZ 0509
LMN 050C
PQR 050F
HIJ 0512

11) 0535 LDX XYZ EMPR 0200


ALPHA 0200
ABC 0500
XYZ 0509
LMN 050C
PQR 050F
HIJ 0512
12) 0538 END ABC
EMPR 0200
ALPHA 0200
ABC 0500
XYZ 0509
LMN 050C
PQR 050F
HIJ 0512

B) Using a ONE PASS assembler that generates an object file for later execution, find
out the generated object file.
H^EMPR^000200^000338
T^000500^09^000000^0C0000^040000
T^000501^02^0509
T^000509^03^FFFFFF
T^000504^02^050C
T^00050C^03^CDAFEB
T^000507^02^050F
T^00050F^03^505055
T^000532^06^000512^000509
E^000500

Q2) What is the difference between the following sequence of the statements ?
a) LDA #3
Load 3 to accumulator immediately
b) First statement defines THREE and assigns to it 3
And then load the 3 value immediately to acc
Both a and b :
o used the immediate addressing
o aim to load 3 to acc.
o Have same object code
But the syntax is different

c)load the content of three to acc.

Q3) a. firstly load the content of LENGTH to acc and then subtract one from the content of the acc
b.subtract one from LENGTH address and then store the content of(LENGTH-1) to acc

Q4)
• Forward jump to insruction items cannot be easily eliminated
• The linked list created in one pass assembler can be very large and use a lot of memory for loading because the
increasing in the size of object file ,but in two pass assemblers the memory allocated in pass one reused in pass2
• In load and go one pass assembler, there is no object code ,so it is not linked to libraries and it will also be run every
time it is translated
Q5) How would you design the SYMTAB of the ONE PASS load-and-go
Assembler as a data structure in C++?
The structure of symbol table can be map ,the label is a key and the address is the value :
Map[label]=address
And the undefined label stored on linked list, create header node pointer to the addresses that uses this label
PALESTINE POLYTECHNIC UNIVERSITY
COLLEGE OF INFORMATION TECHNOLOGY AND COMPUTER ENGINEERING
SYSTEMS PROGRAMMING - SPRING2020
HOMEWORK #5
INSTRUCTOR: ENG. YOUSEF A. SALAH

Q1) The following program consists of three control sections; Assume the first control section
called PROG1 looks like:

Object
Loc Code
0000 PROG1 START 0
EXTDEF LISTA, ENDA
EXTREF LISTB, ENDB, LISTC, ENDC
...
0020 REF1 LDA LISTA
0023 REF2 +LDT LISTB+4
0027 REF3 LDX #ENDA-LISTA
...
0040 LISTA EQU *
...
0054 ENDA EQU *
0054 REF4 WORD LISTC
0057 REF5 WORD LISTB - 3
005A REF6 WORD LISTA+LISTB
005D REF7 WORD ENDC-LISTC-100
0060 REF8 WORD LISTA-LISTB-ENDA+ENDB
END REF1

Answer the followings:


1) Generate the object code for the instructions and directives in PROG1. (8 Shaded Parts)
2) What is the generated object file of PROG1?
3) Assume PROGADDR = 250016, and the loader loaded PROG1, PROG2 and PROG3
consecutively, and the ESTAB is:

Control Symbol Address Length


Section Name (Hex) (Hex)
PROG1 2500
LISTA
ENDA
PROG2 7F
LISTB 25C3
ENDB 25D3
PROG3 51
LISTC 2612
ENDC 2624

(a) Fill in the missing parts in the ESTAB (5 shaded parts).


(b) Based on 250016 as a PROGADDR, what are the actual values of REF4, REF5, and
REF6 in PROG1?
(c) What is the value of EXEADDR?

Q2)

Q3)
HOMEWORK #5

Name:Latifa Masri

Q1) The following program consists of three control sections; Assume the
first control section
called PROG1 looks like:

Loc ObjectCode

0000 PROG1 START 0

EXTDEF LISTA, ENDA


EXTREF LISTB, ENDB, LISTC, ENDC
...
03201D
0020 REF1 LDA LISTA 77100004
0023 REF2 +LDT LISTB+4 050014
0027 REF3 LDX #ENDA-LISTA

...
0040 LISTA EQU *
...
0054 ENDA EQU *
0054 REF4 WORD LISTC 000000
0057 REF5 WORD LISTB - 3 FFFFFD
005A REF6 WORD LISTA+LISTB 000040
005D REF7 WORD ENDC-LISTC-100 FFFF9C
0060 REF8 WORD LISTA-LISTB-ENDA+ENDB FFFFEC

END REF1
1) Generate the object code for the instructions and directives in PROG1.
(8 Shaded Parts)

0020 REF1 LDA LISTA

Disp = TA – (PC) = 0040 – 0023 = 1D

op n i x b p e Disp
00 1 1 0 0 1 0 1D

Opcode = 03201D

0023 REF2 +LDT LISTB+4

LISTB+4 = 000000+4=000004

op n i x b p e add
74 1 1 0 0 0 1 00004

Opcode = 77100004
M^000024^05^+LISTB

0027 REF3 LDX #ENDA-LISTA

LISTB+4 = 0054 – 0040 =0014

op n i x b p e add
04 0 1 0 0 0 0 014

Opcode = 050014
0054 REF4 WORD LISTC

LISTC= 000000

Opcode = 000000
M^000054^06^+LISTC

0057 REF5 WORD LISTB – 3

+3:0000 0000 0000 0000 0000 0011


-3:1111 1111 1111 1111 1111 1101=FFFFFD
LISTB +(-3)= 000000 + FFFFFD=FFFFFD

Opcode = FFFFFD
M^000057^06^+LISTB

005A REF6 WORD LISTA+LISTB

LISTA +LISTB= 000040 + 000000=000040

Opcode = 000040
M^00005A^06^+PROGA
M^00005A^06^+LISTB

005D REF7 WORD ENDC-LISTC-100

+100: 0000 0000 0000 0000 0110 0100


-100:1111 1111 1111 1111 1001 1100=FFFF9C

ENDC – LISTC + (-100)= 000000 – 000000 + FFFF9C=FFFF9C

Opcode = FFFF9C
M^00005D^06^+ENDC
M^00005D^06^-LISTC
0060 REF8 WORD LISTA-LISTB-ENDA+ENDB

LISTA-LISTB-ENDA+ENDB= 000040 – 000000 - 000054+000000


=000040 – 000054
=-(54-40)
=-(000014)
+14: 0000 0000 0000 0000 0001 0100
-14:1111 1111 1111 1111 1110 1100=FFFFEC

Opcode = FFFFEC
M^000060^06^-LISTB
M^000060^06^+ENDB

2) What is the generated object file of PROG1?

H^PROG1 ^000000^000063
D^LISTA ^000040^ENDA ^000054
R^LISTB ^ENDB ^LISTC ^ENDC
T^000020^0A^03201D^77100004^050014

T^000054^0F^000000^ FFFFFD ^000040^ FFFF9C ^ FFFFEC

M^000024^05^+LISTB
M^000054^06^+LISTC
M^000057^06^+LISTB
M^00005A^06^+LISTB
M^00005A^06^+PROG1
M^00005D^06^+ENDC
M^00005D^06^-LISTC
M^000060^06^-LISTB
M^000060^06^+ENDB
E^000020
3) Assume PROGADDR = 250016, and the loader loaded PROG1, PROG2
and PROG3 consecutively, and the ESTAB is:

Control Symbol Address Length


Section Name (Hex) (Hex)
PROG1 2500 63
LISTA 2540
ENDA 2554
PROG2 2563 7F
LISTB 25C3
ENDB 25D3
PROG3 25E2 51
LISTC 2612
ENDB 2624

(a) Fill in the missing parts in the ESTAB (5 shaded parts).

Start Add PROG1 = 2500


Start Add PROG2= start add PROG1+length PROG1=2500+63=2563
Start Add PROG3= start add PROG2+length PROG2=2563+7F=25E2

LISTA=40 ,at run time LISTA=2500+40=2540


ENDA=40 ,at run time ENDA=2500+54=2554

(b) Based on 250016 as a PROGADDR, what are the actual values of REF4, REF5, and
REF6 in PROG1?

For REF4→0054 :the value stored in it is 000000


M^000054^06^+LISTC
➔000000+2612=002612 stored in 2554
Actual value for ref4 ➔002612

For REF5→0057 :the value stored in it is FFFFFD


M^000057^06^+LISTB
➔ FFFFFD +25C3 =0025C0stored in 2557
Actual value for ref5 ➔0025C0
For REF6→0057 :the value stored in it is 000040
M^00005A^06^+PROG1
M^00005A^06^+LISTB
➔ 000040+2500+25C3 =004B03 stored in 255A
Actual value for ref6 ➔004B03

(c) What is the value of EXEADDR?

EXEADDR=2500+0020=2520

Q2. Suggest a design for a one-pass linking loader. What restrictions (if
any) would be required? What would be the advantages and disadvantages
of such a one-pass loader?

Design:
The result of pass one is ESTAB that assign addresses to all external symbols
and pass 2 performs the actual loading, relocaton and linking

There is some problems and restrictions faced by a one pass linking loader ,the
main problem would be forward referencing , the actuall addresses of external
symbols not defined in current control section then we cant make relocation in
pass one ,so we can make one pass linking loader similar to one pass assembler
such that we can create linked list for all undefined external references point to
locations that used it and after insert it to ESTAB

When the definisin for external symbol encountered ,the references lists for that
symbol is scanned and the proper address is added or subtraction from the
opcode that stored on references locations

the advantages:
avoid the overhead of an additional pass over object program

disadvantages:
requires more memory because the increasing of linked list references
Q3.Suppose that you have been given the task of writing an "unloader" -
that is, a piece of software that can take the image of a program that has
geen loaded and write out an object program that could later be loaded and
executed. The computer system uses a relocating loader, so the object
program you produce must be capable of being loaded at a location in
memory that is different from where your unloader took it. What problems
do you see that would prevent you from accomplishing this task?

The loader loads the program and update there addresses, so


unloader can not return back the addresses as it was because it loss
all information that use it in loading this program as External symbol
table (ESTAB) .
Then we can not define the start and end addresses for each control
section ,and we could not have enough information to return back
modification records because there is no way to determine which
parts the object program have been relocated and there is no way to
tell data items that represent address (required relocation) from those
that represent other types of data
PALESTINE POLYTECHNIC UNIVERSITY
COLLEGE OF INFORMATION TECHNOLOGY AND COMPUTER ENGINEERING
SYSTEMS PROGRAMMING - SPRING2020
HOMEWORK #6
INSTRUCTOR: ENG. YOUSEF A. SALAH

Q1) Given the following macro definition:

RMCR MACRO &BASE, &TIMES


IF (&TIMES EQ 0)
LDA #1
ELSEIF (&TIMES EQ 1)
+LDA &TIMES
ELSE
+LDA &BASE
ENDIF
RMO A, T
&PW SET &TIMES
WHILE (&PW GE 1)
MULR T, A
&PW SET &PW - 1
ENDW
MEND

Answer the followings:


(a) How would this macro expanded for each of the following calls:
1) RMCR NUM, 2
2) RMCR INP, 1
(b) For the following invocation: RMCR N, 5
1) How will the macro be expanded?
2) What are the contents of DEFTAB, NAMTAB, and ARGTAB?
(c) What is the function of this macro?

Q2)
Q3)

Q4) What are the differences between positional parameters and keyword parameters?

Q5) In reference to the Macro processor discussed in the textbook (Page 184-185), Indicate
whether each of the following statements is TRUE or FALSE:
a) The LEVEL variable in the DEFINE procedure is used to keep track with the
beginning and end of each nested macro definition.
b) The Macro processor allows calling a macro inside a macro definition.
c) The Macro processor allows defining a macro inside another macro.
d) When the EXPANDING variable is TRUE the macro processor reads lines from the
source code.
e) Comments are stored in the DEFTAB during macro definition.
f) The logic of this macro processor is used to handle keyword parameters.

Q6) (a) When is it preferable to write a macro instead of a function?


(b) Write a C++ macro that has two parameters A, B and C. The macro will return the
minimum value stored in its parameters.
Systems Programming

Home Work # 6

Latifa Masri

Q1) Given the following macro definition:

Answer the followings:

(a) How would this macro expanded for each of the following calls:

1)RMCR NUM, 2

Sol. &PW =2 1 0, &BASE = NUM


&TIMES = 2

+LDA NUM
RMO A,T
MULR T, A
MULR T, A

2) RMCR INP, 1

Sol. &PW = 1 0, &BASE = INP


&TIMES = 1

+LDA 1
RMO A,T
MULR T, A
(b) For the following invocation: RMCR N, 5
1) How will the macro be expanded?
Sol. &PW = 5 4 3 2 1 0
&BASE = N
&TIMES = 5

+LDA N
RMO A,T
MULR T, A
MULR T, A
MULR T, A
MULR T, A
MULR T, A

2) What are the contents of DEFTAB, NAMTAB, and ARGTAB? DEFTAB

NAMTAB

RMCR &BASE, &TIMES


IF (?2 EQ 0)
LDA #1
ELSEIF (?2 EQ 1)
RMCR +LDA ?2
ELSE
+LDA ?1
ENDIF
RMO A, T
&PW SET ?2
WHILE (&PW GE 1)
MULR T, A
&PW SET &PW - 1
ENDW
MEND
ARGTAB
N

5
(c) What is the function of this macro?

Sol.

Used to find &BASE^(&TIMES+1) Except at &TIMES=1 result will be 1


(multiple of the base (&TIMES+1) of the times)

Sol.

The first code not macro but the second is macro


The sequence in (a) will completlly expanded , testing data on condition
and assignment the BETA will apllied after expansion but in sequence
(b) test data will applied during expansion time ,and if the condition
true (&ALPHA NE 0) then it will expanded and the macro time variable
BETA will assigned 3 to it
Sol.

a) Its not macro , The for loop will be repeatedly executed in the run
time , update values of regester and test the data in the run time
, and while the condition is true(after increment the reg x is still
less than 8) it will repeat the loop as long as the condition is false
(after increment the reg x is equal 8 not less than)

b) While the condition is true(&CTR LT 8) the code inside the while


will still expanded until encountered ENDW and still check the
condition if true then it will repeatedly expanded the code and
change the value of macro time variable that exist in the symbol
table and after expanded is complete , it will test the values of
the arguments
Q4) What are the differences between positional parameters and keyword parameters?

positional parameters keyword parameters

parameters and arguments are Each argument value is written


associated in reference to their within a word that names the
order (position) in both of macro corresponding parameter.
prototype and macro invocation. And the argument may appear in
any order.

If an argument to be omitted (null If an argument (null),don’t put


argument), the invocation anything or specify two
statement should specify two consecutive commas ( , , )
consecutive commas ( , , ) at the at the position of that argument
position of that argument.

No default values are used in this Default values for parameters are
form of parameters. allowed.

Not suitable when a macro has suitable when a macro has large
large number of parameters, and a number of parameters, and a few
few arguments are to be indicated arguments are to be indicated.

This form of invocation is error- More readable, Less error-prone


prone and inconvenient to than positional parameters.
programmer, since it should
follow a strict order in specifying
arguments ,unreadable
Q5) In reference to the Macro processor discussed in the textbook (Page 184-185), Indicate
whether each of the following statements is TRUE or FALSE:

a) The LEVEL variable in the DEFINE procedure is used to keep track with the beginning
and end of each nested macro definition.(True)

b) The Macro processor allows calling a macro inside a macro definition. .(False)

c) The Macro processor allows defining a macro inside another macro. (True)

c) When the EXPANDING variable is TRUE the macro processor reads lines from the source
code. (False)

d) Comments are stored in the DEFTAB during macro definition. (False)

f) The logic of this macro processor is used to handle keyword parameters. (False)

Q6) (a) When is it preferable to write a macro instead of a function?

Sol.

When we need faster execution during the run time ,


when small code is repeated many times
(b) Write a C++ macro that has three parameters A, B and C. The macro will return the
minimum value stored in its parameters

Sol.

#include <iostream>

using namespace std;

#define smallestValue(A,B,C) ((A)<(B) ?((A)<(C)?(A):(C)):((B)<(C)?(B):(C)))


int main()
{
int x,y,z;
cout<<"enter three values to find minimum value: ";
cin>>x>>y>>z;
cout<<"the minimum value is: "<<smallestValue(x,y,z)<<endl;

return 0;
}

Another solution :

#define minFromTwoValues(X,Y)((X)<(Y)?(X): (Y))

#define smallestValue(A,B,C) ((A)<(B)?minFromTwoValues(A,C):minFromTwoValues(B,C))

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy