SP HW Merged
SP HW Merged
Q1) For the following SIC Program, answer the questions that follow:
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.
labelList.append(label)
operationCodeList.append(op)
operandList.append(operand)
commentList.append(comment)
:if op in directive
countDirective+=1
Q1) For the following SIC/XE Program, answer the questions that follow:
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:
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.
EMPR 0200
EMPR 0200
ALPHA 0200
ALPHA 0200
ABC 0500
ABC 0500
XYZ * 0501 0501
XYZ *
LMN *
0504
EMPR 0200
ALPHA 0200
ABC 0500
XYZ 0509
LMN 050C
PQR * 0507
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
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
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
...
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)
op n i x b p e Disp
00 1 1 0 0 1 0 1D
Opcode = 03201D
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
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
Opcode = FFFFFD
M^000057^06^+LISTB
Opcode = 000040
M^00005A^06^+PROGA
M^00005A^06^+LISTB
Opcode = FFFF9C
M^00005D^06^+ENDC
M^00005D^06^-LISTC
0060 REF8 WORD LISTA-LISTB-ENDA+ENDB
Opcode = FFFFEC
M^000060^06^-LISTB
M^000060^06^+ENDB
H^PROG1 ^000000^000063
D^LISTA ^000040^ENDA ^000054
R^LISTB ^ENDB ^LISTC ^ENDC
T^000020^0A^03201D^77100004^050014
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:
(b) Based on 250016 as a PROGADDR, what are the actual values of REF4, REF5, and
REF6 in PROG1?
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?
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.
Home Work # 6
Latifa Masri
(a) How would this macro expanded for each of the following calls:
1)RMCR NUM, 2
+LDA NUM
RMO A,T
MULR T, A
MULR T, A
2) RMCR INP, 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
NAMTAB
5
(c) What is the function of this macro?
Sol.
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)
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.
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)
f) The logic of this macro processor is used to handle keyword parameters. (False)
Sol.
Sol.
#include <iostream>
return 0;
}
Another solution :