Examinable Question and answer system programming
-
Upload
makerere-university -
Category
Education
-
view
3.905 -
download
27
Transcript of Examinable Question and answer system programming
FACULTY OF COMPUTING AND INFORMATION TECHNOLOGY
SYSTEMS PROGRAMMING CSC 2102
TEST 1 Marking Guide
EXAM 2006
A collection of programs whose purpose is to make more effective use of the
computer.
Examples include language processors (compilers and assemblers), loaders,
macro processors, operating systems and file
Programs written by the user for the purpose of solving particular problems
using a computer as a tool e.g. application packages.
Decode the instructions and use them to control the activities within the
system. It also performs the arithmetic and logical computations.
Stores both data and instructions that are currently being used.
� Decode the address of the memory location being accessed.
� Buffer data onto/off the bus.
� Contain circuitry to perform memory reads or write.
1. Immediate Addressing: Information is part of the instruction.
2. Direct addressing: The address is part of the instruction.
3. Register addressing: The operand is in the register and the register’s address
is part of the instruction.
4. Indirect Addressing: The address is in the location whose address is
specified as part of the instruction.
5. Base addressing: The address is formed by adding the contents of a memory
location or register to a number called a displacement which is part of the
instruction.
6. Indexing: It is a process of incrementing or decrementing an address as the
computer sequences through a set of consecutive or evenly spaced addresses.
7. Auto incrementing / decrementing: The index is automatically incremented
by an instruction.
Instructions: They are translated into machine code by the assembler.
e.g. MOV A , M
Directive: Gives directions to the assembler during the assembly process but
they are not translated into machine code. e.g. the directive COST : DS 1
will causes the assembler to reserve a byte and associate a symbol COST to
it
Reserves memory and assigns a label to the first byte of the reserved area.
e.g. ARRAY: DS 20 reserves 20 bytes and assigns the label ARRAY to
the byte with the lowest address.
DB (Define Byte)
Puts values into or pre-assign values to memory locations as well as reserve
space and assign labels. e.g. DATA: DB 5 , puts a value 5 into a reserved
memory location called DATA.
DW (Define Word)
Puts words into or pre-assign values to memory locations as well as reserve
space and assign labels.
RESW Reserve the indicated number of words for a data area.
RESB Reserve the indicated number of bytes for a data area
WORD Generate a one word integer constant
BYTE Generate character or hexadecimal constant, occupying as
many bytes as needed to represent the constant
A Accumulator; used for arithmetic Operations
X Index register; used for addressing
L Linkage register; the Jump to subroutine (JSUB) instruction stores the
return address in this register.
PC Program Counter; Contains the address of the next instruction to be fetched
for execution.
SW Status word; contains the condition codes
B Base register, used for addressing
S General Working register, no special use.
T General Working register, no special use.
F Floating Point Accumulator.
Loads immediate Data 5 in the Accumulator. Addressing
Mode is Immediate
Loads immediate Data 6 in register B. Addressing Mode is
Immediate
Adds contents of register B to contents in register A
Addressing Mode is Register
Stores contents of register A to an address ABCDE
Addressing Mode is Simple
The program loads registers A and B with values 5 and 6 respectively. It
adds the contents of both registers and stores the answer a memory location
whose address is ABCDE
LDA ZERO
STA SUM
LDX SUM
LOOP: LDA SUM
ADD NUMS, X
STA SUM
LDA INDEX
ADD THREE
STA INDEX
COMP K300
JLT LOOP
INDEX RESW 1
RESULT RESW 1
SUM RESW 1
NUMS RESW 100
ZERO WORD 0
K300 WORD 300
FACULTY OF COMPUTING AND INFORMATION TECHNOLOGY
SYSTEMS PROGRAMMING CSC 2102
TEST 2
TEST 2007
Answer all questions
Time allowed: 1 Hour
1. (a) Explain the following (i) SYMTAB
A symbol table; used to hold addresses of symbols used in the
program.
(ii) LOCCTR A Location Counter: used to help in the assignment of addresses. It is
initialized to the beginning address specified in the START statement.
After each source statement is processed the length of the assembled
instruction or data area to be generated is added to the LOCCTR.
(iii) OPTAB Operation Code Table: used to look up and validate operation codes in
the source program. In pass 2 it is used to translate the opcodes to
machine language
(iv) LITTAB Literal table: It contains the literal name, the operand value and the
address assigned to the literal
(b) Two passes are usually used to assemble an Assembler language
program; explain briefly what is accomplished in each pass. Pass 1
(i) The first pass scans the source program for label definitions and
assigns addresses to all statements in the program.
(ii) Saves the addresses assigned to all labels for use in pass 2
(iii) Perform some processing of the assembler directives. e.g., determining
the length of data areas defined by BYTE, RESW etc.
Pass 2 (assemble the instructions and generate machine code)
(i) Assemble instructions (translating operation codes and looking up
addresses)
(ii) Generate data values defined by BYTE, WORD, etc.
(iii) Perform processing of the directives not done during pass 1.
(iv) Write the object program and assembly listing onto some output device
which will later be loaded in memory for execution.
2. Given below is a program PROG that has been written using the SIC/XE
machine. LDT NUM LDA ALPHA ADDR T, A SUB #8 STA SUM1 LDA GAMMA ADDR T,A SUB #12 STA SUM2
ALPHA RESW 1 SUM1 RESW 1 GAMMA RESW 1 SUM2 RESW 1 NUM RESW1 1
(i) Study the program carefully and write mathematical expressions
that correspond to the given code. SUM1 = ALPHA + NUM – 8
SUM2 = GAMMA + NUM - 12
(ii) Assuming that it is to be loaded in memory from 0058H, generate
the corresponding addresses for each instruction and write the corresponding machine code. The operation codes for the instructions are LDT = 74, LDA = 00, ADDR = 90, SUB = 1C, STA = 0C and the addresses for registers A and T are 0 and 5 respectively.
0058 LDT NUM 772022
005B LDA ALPHA 032013
005E ADDR T, A 9050
0060 SUB #8 1D0008
0063 STA SUM1 0F200E
0066 LDA GAMMA 03200E
0069 ADDR T, A 9050
006B SUB #12 1D000C
006E STA SUM2 0F2003
0071 ALPHA RESW 1
0074 SUM1 RESW 1
0077 GAMMA RESW 1
007A SUM2 RESW 1
007D NUM RESW 1
(iii) Write the corresponding text listing for the generated machine instructions. H^ PROG ^000058^000028
T^000058^19^772022^032013^9050^1D0008^0F200E^03200E^9050^1D000C^0F2003
E^000058
3. (a) (i) What is program relocation? Ability of a program to be able to run successfully in memory without
considering the address where it is going to be loaded.
(ii) Explain why some instruction need modification records
during program relocation and others do not. Instruction that have been assembled using addresses are the ones that
need to be modified; format 1, format 2 do need have address
operands; and format 3 instructions that have been assembled using
program counter relative or base relative are similarly not affected
because the displacements do not change when the program is loaded
at different addresses.
(b) Assume the following instruction
0006 LDA NUMBER 2032 NUMBER: WORD 6
(i) Write machine code for the instruction at address 0006 03102032
(ii) Write the modification record for the instruction
M00000705
������������������ �������
�
��������������� �����������
�������
2004
�
���� ���� �������������������������� !!�"�#� ����$��%��#�
� � � ����������������#�� �������������������
System software are programs that control the operation of the machine and carry out the
most basic functions the computer performs. They control the way in which the computer
receives input, produces output, manages and stores data, carries out or executes
instructions of other programs etc. Examples of systems programs include language
processors (compilers and assemblers that accept people like languages and translate them
into machine language), loaders (they prepare machine language programs for execution),
macro processors (allow programmers to use abbreviations), operating systems and file
systems (allow flexible storing and retrieval of information).
Application programs are written by the user for the purpose of solving particular problems
using a computer as a tool e.g. application packages like MSWORD, EXCEL etc.����� & ��������� #�'����#�#����!�����'������"��#������� #���� "�������
The microprocessor
• Decodes the instructions and use them to control the activities within the system
• Performs the arithmetic( + , -, /, *) and logical (>,>=,<,<=, =, =!) computations.
Timing Circuitry (Clock)
Used to synchronise the activities within the microprocessor and the bus control logic.
Memory
Stores both data and instructions that are currently being used. locations.
I/O Devices
Devices for communicating with the external world.
Mass Storage Devices.
Computer components for permanently storing programs and data.
System Bus.
A set of conductors that connect the CPU to its memory and I/O devices. The bus conductors
are normally separated into 3 groups:
• The Data Lines: for transmitting information
• Address Lines: Indicate where information is to come from or where it is to be
placed.
• Control Lines: To regulate the activities on the bus.
Interface
Circuitry needed to connect the bus to a device
�(')� & ��� �#�� ����� #� ���� �� #� '����#�#��� �!� �� ��� '���� � '"��"�'����"���The control unit consisting of:
(i) The Program Counter (PC): It holds the address of the main memory location from
which the next instruction is to be fetched.
(ii) Instruction Register (IR) Receives the instruction when it is brought from memory
and holds it while it gets decoded and executed.
(iii) Processor Status Word (PSW) contains condition flags which indicate the current
status of the CPU and the important characteristics of the result of the previous
instruction.
(iv) Stack Pointer (SP): Accesses a special part of memory called a stack. It hold the
address at the top of the stack.
Working Registers
(i) Arithmetic Registers: They temporarily hold the operands and the result of the
arithmetic operations.
(ii) Address Registers: for addressing data and instructions in main memory.
Arithmetic/Logic Unit
It performs arithmetic and logical operations on the contents of the working registers, the
PC, memory locations etc.. It also sets and clears the appropriate flags.
���� ���� ������������������������� ����������������������������������� � ���������������������
The format of an instruction is the arrangement of the instruction with respect to assigning
meaning to its various groups of bits is called its format.
It consists of
Operation code: The portion of the instruction that specifies what the instruction
Operands: Any address or piece of data that is required by the instruction to complete its
execution
e.g.
Register to register transfer
Opcode Destination Source
(Register B) (Register A)
($) ��������������������� #��#����"����#����*�*+����"��� #,������-�8. Immediate Addressing: Information is part of the instruction. No addressing is
needed to get the information.
e.g. X = 3 + 5 (3 and 5 are constatnts)
9. Direct addressing: The address is part of the instruction.
e.g. X = p + q (where p and q are memory locations)
10. Register addressing: The operand is in the register and the register’s address is part
of the instruction.
e.g. X = A + B (where A and B are registers)
11. Indirect Addressing: The address is in the location whose address is specified as part
of the instruction. This location may be a register (register indirect addressing) or it
may be a memory location.
e.g. add contents of register R1 to the memory location whose address is in register
R2.
12. Base addressing: The address is formed by adding the contents of a memory location
or register to a number called a displacement which is part of the instruction. It is
used primarily to reference arrays or in relocating a program in memory.
e.g X = 5 + B:5 where B is a base register
�.- (�)� / ,�� ,��� ����� ���"��#�� � !!�"�#'��� $��%��#� ���� ���� �#��
�������01����'� #��� SIC SIC/XE
Memory (215
) (220
)
Registers A,X, L, PC, SW Has extra registers namely B, S, T, F
Data Formats No floating point hardware Has a floating point format
0 1 0 0 0 1 1 1
1 11 36
Instruction
Formats
Only one Instruction Format 8 1 15
4 different instruction formats 8
8 4 4
6 1 1 1 1 1 1 12
6 1 1 1 1 1 1 20
Addressing
Modes
Direct and Indexed only Immediate, Indirect, Base Relative,
Program Counter relative, Simple,
Direct
Instruction set Fewer Instructions More Instructions
����� /�%�%���������"����#��$�"�+�-�+�$�����"��� #��������01��!���� #,�
�� #��!�"���!������������������������������������������� � ������������������������������������ �������� � ����������������������� ������������������������������������������������������������������������ ����������������2- 34������#���32�+���"���%����'� #����#,��,�� #��"�'� �#��!�"�����
���01����'� #�-�����'�#��#����!�"�, ���"��15���5��#��6��"�����%#��#�� �� �#������� �!� ����� ����"�� ��'�� �#�� % ��� ��� "� '�#��#��� ����������%#-������ #�( ) 7������'�� #��"�'� �#��''���� ����-�( ) �������"��� #,�����������-�( ) ������",������"������%��"������ '�$��-���"� ��#��#��� �!� ���� "�, ���"�� #8��8��� �!��"� ���'�� �#� �!� ��'��
#��"�'� �#� X PC B
2050 3000 4000
Memory addresses
Opcode n i x b p e displacement
6FAC00 = 011011 11 1 01 0 110000000000
��� ��#�$��%�&''&''�%�(�%�)*��%�)��$�+�,����+���-+�������+��
50 1400 2000
3000 2000 1000
Opcode x address
S exponent fraction
Opcode
Opcode r1 r2
Opcode n i x b p e displacement
Opcode n i x b p e address
S exponent fraction
���� .$$+�����,���$��%�� �����(9 "�'����$$+�����,����#� �����%�'���$���%�'������� ��+,����$$+����/���%�'0���%�'0�$�����#������%�&&�� � � � 1&�2�'3&&�2�&&�%���+����"�� ���������-� �,����+���:�.����
Opcode n i x b p e displacement
064050 = 000001 1 0 0 10 0 000001010000
��� ��#�$��%�&&&&&'�%�&3�%�)*4�%�)��$�+�,����+�4�-+�������+������ .$$+�����,���$��%��#� "�'���$$+�����,����#� �����%�'���$���%�&������� ��+,����$$+����/0���%�'0�$�����#������%�&1&�� � � � �&&&�2�&1&�%���+��
( 8) ���������-� �,����+�4�:�������INSTITUTE OF COMPUTER SCIENCE
SYSTEMS PROGRAMMING CSC 2101
TEST 2
1. Explain the use of the following:
(ii) The OPTAB ��� ����������� ���������� ����� ��� ����� ��� ������������� �������
��� ������� ����� ����� ������� ������� �����
(3 marks)�
(iii) The SYMTAB ������� ������ ������ �������� �������� ��� �������� ������ ���� ���������� (3 marks)
(iv) The LOCCTR
�������������� ������������������������������
������������� ���������
(v) The LITTAB ����������������������������������������������������������������������������������� �������������������������������������������������������������������(3 marks)
2. Assume the following assembler code for the SIC/XE machine
Study the code and briefly explain what is being accomplished
��������������������������������������!�����"�������������� ������ ��� ���� ������������ �������� ��� �##$
(3 marks)
(ii) Generate machine code for the assembler code.
(3 marks each instruction = 27
marks)
(iii) Write the object code for this program as it would appear on
an output device. %&'#�(&))))))&))))*+��&))))))&))))!,&-.)))$&*/))!+&)/))))&)$�)!0&!1�)$!&)2�)0+&,)0!&�)
!/&$1"22)�+&))))))����������������������������������������������������������������������������������������������������������������
(5 marks)
3. (a) What are literals? �������������������������������3���������������������������������������������������������4 5+�25������������$������������
3�����������������������������+�2
(3 marks)
Explain the difference between literals and immediate
operands. Use an
example to explain your answer
����������������������������������������������������������3����������������������������������������������������������������������������������������������������������������������������������������������������������+6��������������������������.��7$�����������$�����������������������������������������������������������)!)))$���))!�� �.��4 5+�25 �����������������������������+�2������������������������������������3������������������������������������)$")!)�������������+�2�������������������������))".���������������������������������������������(8 marks)
4. (a) What is Program Relocation and how is it done? ����� ��������������������������������������3���� ���������������������������������������������3����3������������������������������3������3������������������������������8�������� � ��� ��������� ������� ��� ���� ����� ����������� ��� ������ ��������������������������������9������������������������������������:� ��� ���� ������ ������� ���� ����� ������ �������������������������������������������������������������������������������������������������(3 marks)��
(b) Consider the code below
Write all the Modification Records that may be needed in this
piece of code. Why don’t the other remaining instructions need
modification records? ;�����������#������3���� ���������� ��� ���� ������������ �� ��������)))- �))!$����))"-��;������������������)))-����;)))))*)/�;������������������))!$����;))))!0)/�;����������� ����� �� ))"-� ��� ;))))"*)/�������������������������������������������(6 marks)� ������������������������������������������������������������������������������������������������������������������������.��7$�3������������������������������������������������
�������������������������������������������� �(3 marks)�
Assume that RDREC and WRREC are indifferent
control sections; rewrite the machine code for the
instructions at addresses 0006, 0013 and 0026� � � � � � � � � � � � � � � � � � � �
� � � � � � � � � � � � � � � � � � � � �
� � � � � � � � � � � � � � � � � � � � � (6 marks)
(ii) Modify the program below so that it can run on a
machine that uses only direct addressing like the simple
SIC machine. ))))� �'<� ���#�� )� �
))))� 2�#��� ���� #+��.#� !0))$$�
)))-� ���'� =�>1� #.#+ � 01")))�
)))�� � �.�� �+?(�%� ))))$-�
))).� � �;'� @+#�� "A))".�
))!)� � =+B� +?.2��� $)))!��
))!$� � =�>1� C##+ � 01$)))�
))!*� � =� ���'� $ )))-�
))!�� +?.2��� �.�� +�2� ))))"��
))!.� � ����� 1>22+#� ) ))$,�
))")� � �.��� �%#++� ))))$)�
))"$� � ���� �+?(�%� ) ))$-�
))"-� � =�>1� C##+ � 01$)))�
))"�� +�2� 1<�+� 5+�25� 0/020-�
))".� @+#�� C�#.� )� ))))))�
))$)� �%#++� C�#.� $� )))))$�
))$$� #+��.#� #+�C� !� �
))$-� �+?(�%� #+�C� !� �
))$,� 1>22+#� #+�1� 0),-� �
!)$,� 1>2+?.� � � �
!)$ � � � � �
� � � � �
")))� #.#+ � � � �
� � � � �
$)))� C##+ � � � �
(24 marks)
������������������ �������
�
��������������� �����������
�����.�
��-� ����� #��#��! 8����'� #�� #����#��#�����!���"������-�
(i) An option that allows the selection of alternative sources of input e.g.
INCLUDE program_name (library_name) directs the loader to read the
designated object program from a library and treat it as if it were part of the
primary loader input.
(ii) An option to allow the user to delete external symbols or entire control
sections e.g. DELETE csect_name instructs the loader to delete the named
control section from the set of programs being loaded.
(iii) An option to change external symbols e.g. CHANGE name1, name2 causes
the external symbol name1 to be changed to name2 wherever it appears in the
object programs.
(iv) An option to specify alternative libraries to be searched e.g. LIBRARY
MYLIB will cause library MYLIB to be searched before the standard system
libraries.
(v) Loaders that perform automatic library search may be asked to exclude some
functions that come with the library search e.g. NOCALL STDEV, PLOT,
CORREL will instruct the loader to exclude the said functions. This avoids the
overhead of loading and linking the unneeded routines and saves on memory
space.
(vi) Options to control outputs from the loader. The user can specify whether an
output is needed or not.
(vii) Options to specify whether external references will be resolved by library
search.
(viii) An option to specify the location at which execution is to begin thus overriding
any information given in the object program.
(ix) An option to control whether or not the loader should attempt to execute the
program if errors are detected during the load.
��-� (�)� 7�����"���8�"�����"�,"���;�
Segments of the program that can execute in such a way that segments that are
not needed in memory at any particular time do not get loaded��� �
($)� ��������"�,"�����,��#�����! #���$������!����% #,�8�"������"�'��"�-�
��5����� ��5'�.��
��5����� ��5��6��
��5����� ��57���
�. ���� ��5��
��5����� ��53�*8����
��5����� ��51���
�. ���� ��5'�
��5����� ��5(�5��
��5���� ��59�:8���
��5����� ��5;�<��
�. ���� ��5(�
��5����� ��5=�>��
�
( )� ���"������ ����"�'��"��� �,"����� '����-��
�
�
�
�
�
�
�
�
�( ) 7� '����,��#���'�#�$�� #�����"��������������� ���
��,����"�% �����,��#��<;� Segments H, I, G and A
�( )� �������������#,�����!�������,��#����"�����!����%�=�
��,��#�� &�#,��� ��,��#�� &�#,���
� � ($����)�� � � ($����)�
.� � '&&&� � 5� � 3&&�
6� � ';&&� � :� � ;&&�
� � 3&&&� � �� � '&&&�
*� � �;&&� � <� � ;&&�
�� � ;&&� � >� � �&&&�
� � '&&&�
�
����������������������'��������"� #,����"�����!������"�,"��� ��+����! �������!����% #,���$���$���%��
Segment Starting Address
Relative Actual Length
1 0000 5000 1000
2 1000 6000 1800
3 2800 7800 4000
4 2800 7800 3000
5 5800 A800 1000
6 1000 6000 400
7 1400 6400 1800
8 2C00 7C00 800
9 1400 6400 2000
.- (�)� 7�����"�������� #�!�#'� �#���!���'��� ��";�(i) To generate code to implement meaning of a source program in the
execution domain and
(ii) To provide diagnostics for violations of the programming language
semantics in the source program�
A
B
C D/E
F
G
H/I
J
K
����� ����� #�����!����% #,=�
(i) A grammar
The grammar specifies the form or syntax of legal statements in the
language.
(ii) Lexical Analysis
The task of scanning the source statement, to recognize and classify the
various
(iii) Syntactic Analysis
Recognizing each statement in the program as some language
construct, such as a declaration, or an assignment statement,
described by the grammar
(iv) A token
Tokens are the fundamental building blocks of the language. It might
be a keyword, a variable name, an integer, an arithmetic operator
��#�� *+�?�����+����+����##�+$��,�����������#���,+����+��������������-�+�����
-����?��,����+�������/�(i) .)�:.�@�6��.��A�5.��.�
<exp>
<exp> <term>
<term>
<term> <factor>
<factor>
<factor>
id id id
{ALPHA} - {BETA} * {GAMMA}
(ii) ALPHA DIV (BETA + GAMMA) – DELTA <expr>
<expr> <term>
<term>
<term> <factor>
<expr> <factor>
<factor>
<expr>
<term> <term>
<factor> <factor>
id DIV id + id - id
{ALPHA} {BETA} {GAMMA} {DELTA} �
OR
<term>
<term> <factor>
<factor> <expr>
>
<expr>
<term>
<expr> <term>
<term>
<factor> <factor>
<factor>
id DIV id + id -
id
{ALPHA} {BETA} {GAMMA}
{DELTA} �
(�) �������� ����� "����� ��� �#�� ��� !�"� ���� ,"����"�%�"�����������#��%�"��"����'���% �������� #,���"����<exp> ::= <factor> | <exp> + <factor> | <exp> - factor> | <exp> * <factor>
| <exp> DIV <factor>
9"�%���������%#���"����"���!�"��������"��� �#�(')�( )��$�8���''�"� #,������ ����� ! ���,"����"-�7�����"�$������" ��� !��#�;�
� <expr>
<expr> <factor>
<factor> <expr>
<expr>
<factor>
<expr> <factor>
<term>
<factor>
id DIV id + id -
id
{ALPHA} {BETA} {GAMMA}
{DELTA} ����
(�) ��"��������������#���&�/��9�>�(6����?�����)�@�9�&����� #,��������"���"��"�'���#'����'�# A����
ALPHA DIV (BETA + GAMMA) - DELTA; Id1 DIV ( id2 + id3 ) - id4 ;
MAKERERE UNIVERSITY
INSTITUTE OF COMPUTER SCIENCE
B.SC.CSC 2004/2005 ACADEMIC YEAR
YEAR TWO, SEMESTER I
FINAL EXAMINATION
PAPER CSC2102: SYSTEMS PROGRAMMING
Marking Guide
DATE: - 27TH
JAN 2005
TIME: - 2:00PM - 5:00 P.M.
DURATION: - 3 HOURS
INSTRUCTIONS
Candidates MUST answer ALL questions in section A and any THREE questions from Section B
Section A: (40 marks): All Questions are Compulsory.
1. Use examples to help you differentiate between Systems Software and Application
Software.
System software are programs that control the operation of the machine and carry out
the most basic functions the computer performs. They control the way in which the
computer receives input, produces output, manages and stores data, carries out or
executes instructions of other programs etc. Examples of systems programs include
language processors (compilers and assemblers that accept people like languages
and translate them into machine language), loaders (they prepare machine language
programs for execution), macro processors (allow programmers to use
abbreviations), operating systems and file systems (allow flexible storing and
retrieval of information).
Application programs are written by the user for the purpose of solving particular
problems using a computer as a tool e.g. application packages like MSWORD,
EXCEL etc. (4 Marks)�
2. Use an example to help you explain the Format of the Machine Language
Instruction
The format of an instruction is the arrangement of the instruction with respect to
assigning meaning to its various groups of bits. It consists of
Operation code: The portion of the instruction that specifies what the instruction
Operands: Any address or piece of data that is required by the instruction to complete
its execution
e.g.
Register to register transfer
Opcode Destination Source
(Register B) (Register A) (4 Marks)
3. (a) What are the main functions of an Assembler?
An assembler is a program that accepts as input an assembler language
program and it produces its machine language equivalent along with
information for the loader (2 Marks)
(b) Explain the steps involved in assembling a simple computer program.
� Convert mnemonic operation codes to their machine language
equivalent; e.g. translate STL to 14.
� Convert symbolic operands to their equivalent machine addresses e.g.
translate RETADR to 1033.
� Build the machine instructions in the correct format.
� Convert the data constants into their internal machine representations
e.g. translate EOF to 454F46
� Write the object program and the assembly listing. (4 Marks)
0 1 0 0 0 1 1 1
4. 6FAC00 and 064050 are two machine language instructions for the SIC/XE
machine. The contents of registers X, PC, and B are shown and a snapshot of
some memory locations with their contents is also shown. Explain
(v) What each instruction accomplishes.
(vi) The addressing modes used.
(vii) The target addresses where applicable.
(8 ) Contents of the registers involved after execution of each instruction.� �
X PC B
2050 3000 4000
Memory addresses
Opcode n i x b p e displacement
6FAC00 = 011011 11 1 01 0 110000000000
(iv) Opcode = 011011 = 6C = LDS = Load register S from memory
(v) Addressing mode = Simple (Direct) addressing (because n = 1 and i = 1)
(vi) Target address : x = 1, p = 1, displacement = C00
50 + 1400 + C00 = 2050
(iv) Contents of Register S = 3000 (4 Marks)
Opcode n i x b p e displacement
064050 = 000001 1 0 0 10 0 000001010000
(v) Opcode = 000001 = 04 = LDX = Load register X from memory
(vi) Addressing mode = Indirect addressing (because n = 1 and i = 0)
(vii) Target address :, b = 1, displacement = 050
2000 + 050 = 2050
(iv) Contents of Register X = 2000 (4 Marks)
5. Use relevant examples to help you explain the difference between the following:
��� Program Blocks and Control Sections
Program Blocks are segments of code that are re-arranged within a single object unit
while Control Sections are parts of the program that maintain their identities after
assembly; each section can be loaded and relocated independently of each other.
references in the usual way because the assembler does not know where any other
control section will be loaded at execution time. (2 Marks)
Relevant Examples (2 Marks)
��� EXTDEFS and EXTREFS statements
The EXTDEF statement names symbols called external symbols that are defined in
this control section but may also be used by other sections.
EXTREF names symbols used in this section but are defined elsewhere. (2 Marks)
Relevant Examples (2 Marks)
6. (a) What is LTORG?
50 1400 2000
3000 2000 1000
It is a directive used to indicate where the literal pool has been placed in a
program if they are not put at the bottom of the program. (2 Marks)
(b) Explain what happens when an assembler encounters the LTORG
directive.
It creates a literal pool that contains all the literal operands used since the
previous LTORG or the beginning of the program. (2 Marks)
8. What are the main functions of a compiler?
• To generate code to implement meaning of a source program in the execution
domain and
• To provide diagnostics for violations of the programming language semantics
in the source program. (2 Marks)
9. Explain the following:
(i) A grammar
The grammar specifies the form or syntax of legal statements in the language.
(1 Mark)
(ii) Lexical Analysis
The task of scanning the source statement, to recognize and classify the
various tokens (1 Mark)
(iii) Syntactic Analysis
Recognizing each statement in the program as some language construct, such
as a declaration, or an assignment statement, described by the grammar
(1 Mark)
(iv) A token
Tokens are the fundamental building blocks of the language. It might be a
keyword, a variable name, an integer, an arithmetic operator (1 Mark)
Section B: (60 marks): Attempt only THREE questions from this section.
9. (a) List and explain the main components of a typical microprocessor
• The Program Counter (PC): It holds the address of the main memory location
from which the next instruction is to be fetched. (1 Mark)
• Instruction Register (IR) Receives the instruction when it is brought from
memory and holds it while it gets decoded and executed. (1 Mark)
• Processor Status Word (PSW) contains condition flags which indicate the
current status of the CPU and the important characteristics of the result of the
previous instruction. (1 Mark)
• Stack Pointer (SP): Accesses a special part of memory called a stack. It hold
the address at the top of the stack. (1 Mark)
• Arithmetic Registers: They temporarily hold the operands and the result of
the arithmetic operations. (1 Mark)
• Address Registers: for addressing data and instructions in main memory.
(1 Mark)
• Arithmetic/Logic Unit: It performs arithmetic and logical operations on the
contents of the working registers, the PC, memory locations etc. It also sets
and clears the appropriate flags. (1 Mark)
(b) List and state the uses of the registers found in the SIC/XE
microprocessor.
A Accumulator: used for arithmetic Operations
X Index register: used for addressing
L Linkage register: the Jump to subroutine (JSUB) instruction stores the return
address in this register.
PC Program Counter: Contains the address of the next instruction to be fetched
for execution.
SW Status word: contains the condition codes
B Base register: used for addressing
S General Working register: no special use.
T General Working register: no special use.
F Floating Point Accumulator: For floating point arithmetic (1/2 mark each)
(b) List all the registers of the Intel 8085 microprocessor that have similar
functions like those ones listed in part (b) above.
SIC/XE Intel 8085
Accumulator (A) Accumulator
Linkage Register (L) Stack Pointer
Program Counter (PC) Program Counter (PC)
Status Word (SW) Processor Status Word (PSW)
General Working Registers
(S, T)
General Working Registers
(B, C, D, E, H, L)
(4 Marks)
(c) Explain the formats of the machine language instructions for the SIC/XE
computer.
Format 1 (1 byte)
8
Format 2 (2 bytes)
8 4 4
Format 3 (3 bytes)
6 1 1 1 1 1 1 12
Format 4 (4 bytes)
6 1 1 1 1 1 1 20
(4 Marks)
10. (a) An array ARR1 at a memory location 0030 contains 10 integers. Write a
SIC/XE Assembler Language program that will add up all the integers of
this array and store the answer at a memory location GREATER if the
answer is greater than 100 or at a memory location LESS if the answer is
less than 100
LDS #3
LDT #30
LDX #0
LDA ARR1, X
LOOP : ADDR S, X
ADD ARR1, X
Opcode
opcode r1 r2
opcode n i x b p e disp
opcode n i x b p e address
COMPR X, T
JLT LOOP
COMP #100
JLT SMALLER
STA GREATER
J OUT
SMALLER STA LESS
OUT
ARR1 RESW 10
GREATER RESW 1
LESS RESW 1 (10 Marks)
(b) Assume that the program is to be assembled from memory location 000H
and that GREATER is at a memory location after the array ARR1 and
LESS is at a memory location next to GREATER generate machine code
for this program using Appendix C
Addresses Label Instruction Operand Machine Code
0000 ADDINT START 0
0000 LDS #3 6D0003
0003 LDT #30 75001E
0006 LDX #0 050000
0009 LDA ALPHA, X 03A014
000C LOOP: ADDR S ,X 9041
000E ADD ALPHA,X 1BA00F
0011 COMPR X,T A015
0013 JLT LOOP 3B2FF6
0016 COMP #100 290064
0019 JLT SMALLER 3B2006
001C STA GREATER 0F202F
001F J OUT 3F2003
0022 SMALLER STA LESS 0F202A
0025 OUT
0030 ARR1: RESW 10
004E GREATER: RESW 1
004F LESS RESW 1
(10 Marks)
11. (a) Explain the following terms used in Systems Programs:
(i) Assembling
Produce machine code and Assembler Listing from an assembler
language. (1 Mark)
(ii) Loading
bring the object program into memory for execution. (1 Mark)
(iii) Relocation
modify the object program so that it can be loaded at an address
different from the location originally specified. (1 Mark)
Linking
Combine two or more separate object programs and supplies the
information needed to allow references between them (1 Mark)
(b) Briefly explain one of the methods that may be used to assemble a
program in one pass.
One method produces object code directly in memory for immediate execution.
In this method no object program is written out and no loader is needed (load
and go). It avoids the overhead of writing the object program out and reading
it back in. The assembler generates object code instructions as it scans the
source program. If the operand is a symbol that has not yet been defined, the
operand address is omitted when the instruction is assembled. The symbol
used as an operand is entered in the symbol table. This entry is flagged as
undefined. When the definition for the symbol is encountered the symbol table
is scanned and the proper address is inserted into any instructions previously
generated. Any SYMTAB entries that are still undefined at the end of the
program are flagged by the assembler as errors.
The second type of a one pass assembler produces object code as output is
needed on systems where external working storage devices are not available.
Forward references are entered into lists as before but when the definition of
the symbol is encountered another text record with the correct operand
address is generated. When the program is loaded, this address will be
inserted into the instruction by the action of the loader. (5 Marks)
(c) (i) What are Overlay programs?
They are segments of the program that can execute in such a way that
segments that are not needed in memory at any particular time do not
get loaded��������������������������������� (1 Mark)
(ii) The structure below shows 14 different control sections making up
an overlay structure. The number of bytes each control section
uses is also indicated within the particular section. Write
statements which can be used to create this structure.
SEGMENT SEG(A) PARENT SEG(A)
A
1000
H
900
C
500
B
2000
D/E
1000
G
700
I
1000
F
800
M
200
N
2000
J
2500
K/L
1000
O
850
P
900
SEGMENT SEG(B) SEGMENT SEG(H)
SEGMENT SEG(C) SEGMENT SEG(K/L)
SEGMENT SEG4(D/E) SEGMENT SEG(O)
SEGMENT SEG(F) SEGMENT SEG(P)
PARENT SEG(C) PARENT SEG(H)
SEGMENT SEG(M SEGMENT SEG(J)
SEGMENT SEG(N) PARENT SEG(A)
PARENT SEG(A) SEGMENT SEG(I)
SEGMENT SEG(G) (5 Marks)
(iii) Assuming the overlay structure of the control sections above,
complete the following table for all the control sections shown.
Segment Starting Address
Relative Actual Length
A 0000 2500 1000
B 1000 3500 2000
C 3000 5500 500
D/E 3500 5A00 1000
F 4500 6A00 800
M 3500 5A00 200
N 3700 5C00 2000
G 1000 3500 700
H 1000 3500 900
J 1900 3E00 2500
K/L 1900 3E00 1000
O 2900 4E00 850
P 3150 5650 900
I 1000 3500 1000
(5 Marks)
12 (a) The program below consists of three different control sections; write
down the machine code for the instructions and directives for control
section PROGA.
0000 PROGA START 0 MACHINE CODE EXTDEF LISTA,ENDA EXTREF LISTB, ENDB,LISTC,ENDC . 0020 REF1 LDA LISTA 03201D 0023 REF2 +LDT LISTB + 4 77100004 0027 REF3 LDX #ENDA - LISTA 050014 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
(5 Marks)
(b) Write down the object code for PROGA as it would appear on an output
device.
H^PROGA ^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^+PROGA
M^00005D^06^+ENDC
M^00005D^06^-LISTC
M^000060^06^-LISTB
M^000060^06^+ENDB
E^000020 (5 Marks)
(c) Draw an external symbol table (ESTAB) for this program assuming that
PROGA is to be loaded from a memory location 2500 and that PROGB
immediately follows PROGA and PROGC immediately follows PROGB.
Control Section Symbol Name Address Length
PROG A 2500 0063
LISTA 2540
ENDA 2554
PROGB 2563 007F
LISTB 25C3
ENDB 25D3
PROGC 25E2 0051
LISTC 2612
ENDC 2624
(4 Marks)
(d) Using the assumptions made in part (c) above to calculate the values for
REF4, REF5 and REF6
REF4 = LISTC = 2612 (2 Marks)
REF5 = LISTB – 3 = 25C3 – 3 = 25C0 (2 Marks)
REF6 = LISTA + LISTB = 2540 + 25C3 = 4B03 (2 Marks)
13 (a) Draw top down parse trees according to the grammar in Appendix A for
the following expressions:
(i) ALPHA – BETA * GAMMA
<exp>
<exp> <term>
<term>
<term> <factor>
<factor>
<factor>
id id id
{ALPHA} - {BETA} * {GAMMA} (5 marks)
(ii) ALPHA DIV (BETA + GAMMA) – DELTA
<expr>
<expr> <term>
<term>
<term> <factor> <factor>
<factor>
<expr>
<expr> <term>
<term>
<factor> <factor>
id DIV ( id + id ) - id
{ALPHA} {BETA} {GAMMA} {DELTA}
(5 marks)
(b) Use a bottom up method to parse the following statements using the
operator precedence table in Appendix B. Assume that a semicolon
preceded the given expressions.
(i) SUMQ := SUMQ + VALUE * VALUE;
(ii) ANS:= ALPHA DIV (BETA + GAMMA) – DELTA ;
SUMQ := SUMQ + VALUE * VALUE; Id1 := id2 + id3 * id4 ; <N1>
< = < >
id2
{SUMQ}
Id1 := <N1> + id3 * id4 ; <N2>
< = < < N2 >
id3
{VALUE}
Id1 := <N1> + <N2> * id4 ; <N3>
< = < < < >
id4
{VALUE}
Id1 := <N1> + <N2> * <N3> ; <N4>
< = < < N4 >
<N2> * <N3>
id1 := <N1> + <N4> ; <N5>
< = < N5 >
<N1> + <N4>
id1 := <N5> ; <N6>
< N6 >
id1 := <N5>
<N6>
<N5>
<N1> <N4>
<N2> <N3>
id1 := id2 + id3 * id4
{SUMQ} {SUMQ} {VALUE} {VALUE}
(10 marks)
ANS:= ALPHA DIV (BETA + GAMMA) – DELTA ; id1 := id2 DIV ( id3 + id4 ) - id5 ; <N1>
< = < N1 >
id2
{ALPHA}
id1 := <N1> DIV ( id3 + id4 ) - id5 ; <N2>
< = < < < N2 >
id3
{BETA}
id1 := <N1> DIV ( <N2> + <N3> ) - id5 ; <N3>
< = < < < N4 >
id4
{GAMMA}
id1 := <N1> DIV ( <N4> ) - id5 ; <N4>
< = < < N5 >
<N2> + <N3>
id1 := <N1> DIV <N5> - id5 ; <N5>
< = < N6 >
( <N4> )
id1 := <N6> - id5 ; <N6>
< = < < N7 > <N7>
id1 := <N6> - <N7> ; id5
< = < N8 > <N1> DIV <N5> {DELTA}
<N8> <N9>
id1 := <N8> ;
< = <N9> >
<N6> - <N7> id1 := <N8>
<N9>
<N8>
<N6> <N7>
<N1> <N5>
<N4>
<N2> <N3>
id1 := id2 DIV ( id3 + id4 ) - id5
{ANS} {ALPHA} {BETA} {GAMMA} {DELTA}
���� 9�1���1. <prog> ::= PROGRAM <prog-name> VAR <dec-list> BEGIN <stmt-list> END
2. <prog-name>::= id
3. <dec-list> ::= <dec> | <dec-list> ; <dec>
4. <dec> ::= <id-list> : <type>
5. <type> ::= INTEGER
6. <id-list> ::= id | <id-list> , id
7. <stmt-list> ::= <stmt> | <stmt-list> ; <stmt>
8. <stmt> ::= <assign> | <read> | <write> | for
9. <assign> ::= id := <exp>
10. <exp> ::= <term> | <exp> + <term> | <exp> - <term>
11. <term> ::= <factor> | <term * <factor> | <term> DIV <factor>
12. <factor> ::= id | int | ( <exp>)
13. <read> ::= READ ( <id-list> )
14. <write> ::= WRITE ( <id-list> )
15. <for> ::= FOR <index-exp> DO <body>
16. <index-exp> ::= id := <exp> TO <exp>
17. <body> ::= <stmt> | BEGIN <stmt-list> END
��
���� 9�1�6��
VAR BEGIN END INTEGER FOR READ WRITE TO DO ; : , := + - * DIV ( ) id int
PROGRAM = < VAR = < < < < BEGIN = < < < < < END > > INTEGER > = > < FOR READ = WRITE = TO > < < < < < < < DO < > < < < > <
; > > < < < > < < <
: > < >
, =
:= > = > < < < < < < <
+ > > > > > > < < < > < <
- > > > > > > < < < > < <
* > > > > > > > > < > < <
DIV > > > > > > > > < > < <
( > < < < < < < = < <
) > > > > > > > > >
Id > > > > > > > = > > > > >
Int > > > > > > > > >
APPENDIX C
SIC/XE INSTRUCTION SET
MNEMONIC FORMAT OPCODE EFFECT Notes
ADD m 3/4 18 A (A) + (m...m+2)
ADDF m 3/4 58 F (F) + (m...m+5) X F
ADDR r1,r2 2 90 r2 (r2) + (r1) X
AND m 3/4 40 A (A) & (m…m+2)
CLEAR r1 2 B4 r1 0 X
COMP m 3/4 28 (A) : (m…m+2) C
COMPF m 3/4 88 (F) : (m…m+5) X F C
COMPR r1,r2 2 A0 (r1) : (r2) X C
DIV m 3/4 24 A (A) / (m….m+2)
DIVF m 3/4 64 F (F) / (m….m+5) X F
DIVR r1,r2 2 9C r2 (r2) / (r1) X
FIX 1 C4 A (F) convert to integer X F
FLOAT 1 C0 F (A) convert to float X F
HIO 1 F4 Halt I/O channel number (A) P X
J m 3/4 3C PC m
JEQ m 3/4 30 PC m if CC set to =
JGT m 3/4 34 PC m if CC set to >
JLT m 3/4 38 PC m if CC set to <
JSUB m 3/4 48 L (PC); PC m
LDA m 3/4 00 A (m..m+2)
LDB m 3/4 68 B (m..m+2) X
LDCH m 3/4 50 A [rightmost byte] (m)
LDF m 3/4 70 F (m..m+5) X F
LDL m 3/4 08 L (m..m+2)
LDS m 3/4 6C S (m..m+2) X
LDT m 3/4 74 T (m..m+2) X
LDX m 3/4 04 X (m..m+2)
LPS m 3/4 D0 Load processor status from P X
MUL m 3/4 20 A (A) * (m..m+2)
MULF m 3/4 60 F (A) * (m..m+5) X F
MULR r1,r2 2 98 r2 (r2) * (r1) X
NORM 1 C8 F (F) normalised X F
OR m 3/4 44 A (A) | (m..m+2)
RD m 3/4 D8 A [rightmost byte] data from P
RMO r1,r2 2 AC r2 (r1) X
RSUB 3/4 4C PC (L)
SHIFTL r1,n 2 A4 r1 (r1) left shift n bits X
SHIFTR r1,n 2 A8 r1 (r1) right shift n bits X
SIO 1 F0 Start I/O channel number (A) P X
SSK m 3/4 EC Protection key for address m P X
STA m 3/4 0C m..m+2 (A)
STB m 3/4 78 m..m+2 (B) X
STCH m 3/4 54 m (A) [rightmost byte]
STF m 3/4 80 m..m+5 (F) X F
STI m 3/4 D4 Interval timer value (m ..m+2) P X
STL m 3/4 14 m..m+2 (L)
STS m 3/4 7C m..m+2 (S) X
STSW m 3/4 E8 m..m+2 (SW) P
STT m 3/4 84 m..m+2 (T) X
STX m 3/4 10 m..m+2 (X)
SUB m 3/4 1C A (A) - (m..m+2)
SUBF m 3/4 5C F (F) - (m..m+5) X F
SUBR r1,r2 2 94 r2 (r2) – (r1) X
SVC n 2 B0 Generate SVC Interrupt X
TD m 3/4 E0 Test Device specified by (m) P C
TIO 1 F8 Test I/O channel number (A) P X C
TIX m 3/4 2C X (X) + 1; (X) : (m..m+2) C
TIXR r1 2 B8 X (X) + 1; (X) : (r1) X C
WD m 3/4 DC Device specified by (m) (A) P
MAKERERE UNIVERSITY
FACULTY OF COMPUTING & INFORMATION TECHNOLOGY
END OF SEMESTER I EXAMINATION 2005/2006
PROGRAMME: Bachelor of Science in Computer Science
YEAR OF STUDY: Year II
COURSE NAME: Systems Programming
COURSE CODE: CSC 2102
DATE: 1st December 2005 TIME: 4.00p.m.-7.00 p.m.
Section A: (60 marks): All Questions are Compulsory.
1. (a) What is Systems Software?
A collection of programs whose purpose is to make more effective use of the
computer by controlling the operation of the machine and carry out the most
basic functions the computer performs. They control the way in which the
computer receives input, produces output, manages and stores data, carries
out or executes instructions of other programs etc (2 marks)
(b) List any three Systems software and explain their functions.
(i) Compilers: Translate high level languages to machine language
(ii) Assemblers: Translate Assembler languages to machine language
(iii) Loader: Prepare machine language programs for execution
(iv) Macro processors: allow programmers to use abbreviations
(v) Operating systems and file systems allow flexible storing and retrieval
of information. (3 marks)
2. (a) Explain the following:
(i) Operation Code
The portion of the instruction that specifies what the instruction does.
(1 mark)
(ii) Operand
Any address or piece of data that is required by the instruction to
complete its execution (1 mark)
(iii) Destination
The location that is changed or where the source operand is taken
(1 mark)
(b) Use examples to help you explain the difference between an instruction
and a Directive
An instruction is translated into machine code by the assembler
e.g. LDA NUM (1 mark)
A Directive gives directions to the assembler during the assembly process but
is not translated into machine code e.g. COST : DS 1 (1 mark)
3. How will the following be stored using the SIC/XE machine?
(i) A real number - 15.25
-15.25 = - 1111.01 = -0.111101 x 24
Exponent = 1024 + 4 = 1028 = 10000000100
1 10000000100 111101 = CO4F40000000 (2 marks)
(b) An integer -15
To be changed to 2’s complement.
15 = 1111 = 000000000000000000001111
= 111111111111111111110001 = FFFFF1 (2 marks)
4. (a) What are the basic functions of an assembler?
It accepts as input an assembler language program and it produces its
machine language equivalent along with information for the loader
(2 marks)
(b) Give the tables usually needed in assembling a machine language
program and state their uses.
(i) Symbol Table (SYMTAB)
A table used to store addresses assigned to labels. (1½ marks)
(ii) Operation Code Table (OPTAB)
A table used to look up mnemonic operation codes and translate them
into their machine language equivalents. (1½ marks)
(iii) Literal Table(LITTAB)
It contains the literal name, the operand value and the address
assigned to the operand when it is placed in the literal pool. (1 mark)
5. Assume the following SIC/XE code
0016 LDA @Num1
0050 Num1 BYTE 0100H
0100 Num2 BYTE 0050H
(i) What does the instruction at address 0016 do and what is the addressing
mode used?
It loads 0050H into the accumulator. Addressing Mode is Indirect Addressing
(2 marks)
(ii) Write machine code for this instruction.
Displacement = 0050 – 0019 = 037
Opcode n i x b p e displacement
000000 1 0 0 0 1 0 0 3 7 = 022037 (3 marks)
6. (a) What is Program Relocation?
Ability of loading a program anywhere in memory without stating the actual
starting address (1 mark)
(b) Assume the following SIC/XE instruction and write a modification
records for it. 0016 +LDA Number
M000001705 (2 marks)
7. (a) How are literals different from immediate operands?
With immediate addressing the operand value is assembled as part of the
machine instruction. With a literal the assembler generates the specified value
as a constant at some other memory location. The address of this generated
constant is used as the target address for the machine instruction. (2 marks)
(b) What is the difference between Absolute expressions and Relative
expressions?
An absolute expression contains only absolute terms or relative terms so long
as the relative terms occur in pairs and the terms in each pair have opposite
signs. A relative expression is one in which all the relative terms except one
can be paired. The remaining unpaired relative term must have a positive.
(2 marks)
8. (a) What is the basic function of a loader?
It brings an object program into memory and it start executing it. (1 mark)
(b) Explain the following abbreviations
(i) ESTAB
External symbol table: It is used to store names and addresses of each
external symbol in the set of control sections being loaded. It also
indicates in which control section the symbol is defined. (1 mark)
(ii) PROGADDR
It is the beginning address in memory where the linked program is loaded. Its
value is supplied to the loader by the operating system. (1 mark)
(iii) CSADDRR
CSADDR is the starting address assigned to the control section currently
being scanned by the loader. (1 mark)
9. (a) Explain the following:
(i) A Grammar
The grammar specifies the form or syntax of legal statements in the
language. (1 mark)
(ii) A Token
The fundamental building blocks of the language (1 mark)
(b) State the difference between the SYNTAX and SEMANTICS of a
grammar.
The syntax is the description of the form of legal statements in the language
while the Semantics is the meaning of the statements (2 marks)
Section B: (60 marks): Attempt only THREE questions from this section.
10. (a) List and explain the uses of the main components of a typical computer
The microprocessor
Decode the instructions and use them to control the activities within the
system. It also performs the arithmetic and logical
Timing Circuitry (Clock)
Used to synchronise the activities within the microprocessor and the bus
control logic.
Memory
Stores both data and instructions that are currently being used. address.
The I/O Devices
Devices for communicating with the external world
Mass Storage Devices
Used for storing large quantities of information.
System Bus.
A set of conductors that connect the CPU to its memory and I/O devices.
Interfaces
Circuitry needed to connect the bus to a device.
Bus Control Unit
Co-ordinates the CPU activities with the external world. (14 marks)
(b) List and explain the uses of the registers found in the control unit of a
typical microprocessor.
The Program Counter (PC)
It holds the address of the main memory location from which the next
instruction is to be fetched.
Instruction Register (IR)
Receives the instruction when it is brought from memory and holds it while it
gets decoded and executed.
Processor Status Word (PSW)
Contains condition flags which indicate the current status of the CPU and the
important characteristics of the result of the previous instruction.
Stack Pointer (SP):
Accesses a special part of memory called a stack. It is used to temporarily
store important information while sub routines are being executed. It hold the
address at the top of the stack (6 marks)
11. (a) An array ARR1 contains 20 words of both positive and negative integers.
Write a SIC/XE program that will add up all these integers and store the
sum at a memory location POSIT if the sum is positive or NEGAT if the
sum is negative.
LDS #3
LDS #60
LDX #0
STX SUM
LOOP: LDA NUMBER, X
ADD SUM
STA SUM
ADDR S, X
COMPR X, T
JLT LOOP
LDS #0
COMPR A, S
JLT NEGATIVE
STA POSIT
J OUT
NEGATIVE: STA NEGAT
OUT: (10 marks)
(b) Generate machine code for the first five executable instructions of your
program assuming that the program is loaded from an address 0000H,
the beginning address of ARR1 is 1000H, memory location POSIT is at a
memory location 2000H and NEGAT is at a memory location 3000H
0000 ADD START 0000 0000 FIRST LDS #3 6D0003 0003 LDT #60 75003C 0006 LDX #0 050000 0009 STX SUM 132027 000C LOOP LDA ARR1, X 03AFF1 000F ADD SUM 1B2021 0012 STA SUM 0F201E 0015 ADDR S ,X 0018 COMPR X, T 001B JLT LOOP 001E LDS #0 0021 COMPR A , S 0024 JLT NEGATIVE 0027 STA POSIT 002A J OUT 002D NEGATIVE STA NEGAT 0030 OUT 0033 SUM RESW 1 1000 ARR1 RESW 20 2000 POSIT RESW 1 3000 NEGAT RESW 1
(10 marks)
12. (a) An Assembler Language program is assembled usually in two passes.
Why do we need these two passes? Explain briefly what is done in each
pass.
Addresses of the labels are not known.
Pass 1 (Define symbols)
• Scans the source program for label definitions and assigns addresses
to all statements in the program.
• Saves the addresses assigned to all labels for use in pass 2
• Perform some processing of the assembler directives. e.g., determining
the length of data areas defined by BYTE, RESW etc.
Pass 2 (assemble the instructions and generate machine code)
• Assemble instructions (translating operation codes and looking up
addresses
• Generate data values defined by BYTE, WORD, etc.
• Perform processing of the directives not done during pass 1.
• Write the object program and assembly listing onto some output device
which will later be loaded in memory for execution. (5
marks)
Slightly modify the above piece of code so that it can be assembled in one
pass. 1000 COPY START 1000 1000 EOF BYTE C’EOF’ 454F46 1003 THREE WORD 3 000003 1006 ZERO WORD 0 000000 1009 RETADR RESW 1 100C LENGTH RESW 1 100F BUFFER RESB 4096 200F FIRST STL RETADR 141009 2012 CLOOP JSUB RDREC 480000 2015 LDA LENGTH 00100C 2018 COMP ZERO 281006 201B JEQ ENDFIL 300000 201E JSUB WRREC 480000 2021 J CLOOP 3C2012 2024 ENDFIL LDA EOF 001000 2027 STA BUFFER 0C100F 202A LDA THREE 001003 202D STA LENGTH 0C100C 2030 JSUB WRREC 480000 2033 LDL RETADR 081009 2036 RSUB 4C0000
(5 marks)
Generate the text listing for the above code assuming a one pass
assembler that generates object code on an output device.
H^COPY ^001000^001039
T^001000^09^454F46^000003^000000
T^00200F^15^141009^480000^00100C^281006^300000^480000^3C2012
T^00201C^02^2024
T^002024^19^001000^0C100F^001003^0C100C^480000^081009^4C0000
(10 marks)
13. (a) List and explain any five common loader options.
(i) An option that allows the selection of alternative sources of input e.g.
INCLUDE program_name (library_name) directs the loader to read the
designated object program from a library and treat it as if it were part of
the primary loader input.
(ii) An option to allow the user to delete external symbols or entire control
sections e.g. DELETE csect_name instructs the loader to delete the
named control section from the set of programs being loaded.
(iii)An option to change external symbols e.g. CHANGE name1, name2
causes the external symbol name1 to be changed to name2 wherever it
appears in the object programs.
(iv) An option to specify alternative libraries to be searched e.g. LIBRARY
MYLIB will cause library MYLIB to be searched before the standard
system libraries.
(v) Loaders that perform automatic library search may be asked to exclude
some functions that come with the library search e.g. NOCALL STDEV,
PLOT, CORREL will instruct the loader to exclude the said functions. This
avoids the overhead of loading and linking the unneeded routines and
saves on memory space.
(vi) Options to control outputs from the loader. The user can specify whether
an output is needed or not.
(vii) Options to specify whether external references will be resolved by
library search.
(viii) An option to specify the location at which execution is to begin thus
overriding any information given in the object program.
(ix) An option to control whether or not the loader should attempt to execute
the program if errors are detected during the load. (5 marks)
( b) Given below is piece of code for a control section. There are also other
control sections in memory referencing this section. Assume that the
variables LENGTH and BUFFER of this section are referenced by other
control sections.
(i) Rewrite the piece of code above to reflect these assumptions.
0000 COPY START 0 EXTDEF LENGTH, EXTREF RDREC, 0000 FIRST STL RETADR 17202D 0003 LDB #LENGTH 69202D BASE LENGTH 0006 CLOOP +JSUB RDREC 4B100000 000A LDA LENGTH 032026 000D COMP #0 290000 0010 JEQ ENDFIL 332007 0013 +JSUB WRREC 4B100000 0017 J CLOOP 3F2FEC 001A ENDFIL LDA EOF 032010 001D STA BUFFER 0F2016 0020 LDA #3 010003 0023 STA LENGTH 0F200D 0026 +JSUB WRREC 4B100000 002A J @RETADR 3E2003 002D EOF BYTE C’EOF’ 454F46 0030 RETADR RESW 1 0033 LENGTH RESW 1 0036 BUFFER RESB 4096
(5 marks)
(ii) Generate a text listing for this code.
H^COPY ^000000^000039
D^LENGTH^000033^BUFFER^000036
R^RDREC ^WRREC
T^000000^1D^17202D^69202D^4B100000^032026^290000^332007^4B100000^3F
2FEC^032010
T^00001D^13^0F2016^010003^0F200A^4B100000^3E2000^454F46
M^000007^05^+RDREC
M^000014^05^+WRREC
M^000027^05^+WRREC
E^000000 (10
marks)
14. (a) What are programs with Overlay Structures?
They are segments of a program that can execute in such a way that
segments that are not needed in memory at any particular time do not get
loaded in memory. (3 marks)
(b) Assume program segments defined by the following Overlay structure.
SEGMENT SEG1(A)
SEGMENT SEG2(B)
SEGMENT SEG3(C)
PARENT SEG2
SEGMENT SEG4(D/K)
PARENT SEG1
SEGMENT SEG5(E)
SEGMET SEG6(F)
PARENT SEG5
SEGMENT SEG7(G)
PARENT SEG1
SEGMENT SEG8(H/L)
SEGMENT SEG9(I)
PARENT SEG8
SEGMENT SEG10(J)
i. Express this structure diagrammatically
(5 marks)
A
B
C D/K
E
F G
H/L
I J
(ii) Which segments can be in memory at the same time together with
segment J.
Segments A , H and L (2 marks)
(iii) Assume the lengths of the segments are as follows:
Segment Length Segment Length
(bytes) (bytes)
A 1000 G 400
B 1800 H 800
C 4000 I 1000
D 2800 J 800
E 800 K 2000
F 1000 L 2000
Assume also that the actual starting address of the program is 5000 fill
the following table below.
Segment Starting Address
Relative Actual Length
1 0000 5000 1000
2 1000 6000 1800
3 2800 7800 4000
4 2800 7800 4800
5 1000 6000 800
6 1800 6800 1000
7 1800 6800 400
8 1000 6000 2800
9 3800 8800 1000
10 3800 8800 800
(10 marks)
FACULTY OF COMPUTING AND INFORMATION TECHNOLOGY
SYSTEMS PROGRAMMING CSC 2102
TEST 1
A study of the functions and structures of the programs used by the
system
A collection of programs whose purpose is to make more effective
use of the compute by controling the operation of the machine and
carry out the most basic functions the computer performs. They
control the way in which the computer receives input, produces
output, manages and stores data, carries out or executes instructions
of other programs etc
(i) Compilers: Translate high level languages to machine language
(ii) Assemblers: Translate Assembler languages to machine language
(iii) Loader: Prepare machine language programs for execution
(iv) Macro processors: allow programmers to use abbreviations
(v) Operating systems and file systems allow flexible storing and
retrieval of information.
b p Addressing Mode Target Address
0 0 Direct TA = Disp + (X)
0 1 PC Relative TA = (PC) + Disp + (X)
1 0 Base Relative TA = (B) + Disp + (X)
1 1 -----
n i Addressing Mode Operand
0 0 Simple Addressing Operand = Contents of TA (bits b,p,e are part of address bits)
0 1 Immediate Operand = TA
1 0 Indirect Addressing Word at TA is the address of the Operand
1 1 Simple addressing Operand = Contents of TA
Opcode R1 R2
Opcode n i x b p e Displacement
Opcode n i x b p e address
Explanation
Examples
Property SIC SIC/XE Memory 215 bytes 220 bytes
Registers 5 ( A, X, L, PC,W) Extra registers (B, S, T, F)
Instruction Formats Only 1 Format 4 different Formats
Addressing Modes Only 2 (Direct, Index) 5 (Immediate, Indirect, Direct, PC and Base
Data Formats No Floating Point Format Has Floating Point Format
(b)
.
SIC Intel 8085 A Accumulator
L Stack Pointer
PC Program Counter
SW Processor Status Word
� � � �
-21.25 = -10101.01 = -0.1010101 x 25
Exponent = 1024 + 5 = 1029 = 10000000101
=> 1 10000000101 101010100000000
= C 0 5 A A 0 0 0 0 0 0 0
= C05AA0000000
� � � �
- 15 = -1111 = -000000001111
invert bits and add 1 = 111111110000 + 1 = 111111110001
+- � � � �.������ � � �������� � � �42����
���?�� ���"�� �+�� ��+��� ��#����� ���, �,�� ����+ #������ -�+� ���� ��84����#�����?��#���+�����# ��$������-��+���������+������#���������-�+�,����+��40��0� ��$� 6� �+�� ���?�� ��$� #�������� �-� ����� ����+�� ��#������� ?���� ����+�#���������+����������?��������������� B������#������+ #������##�������������� �����$$+�����,���$��� ��$������#������+ #���������� ������+,����$$+������-�+���#������+ #����������� B���������������������$��-������+�,+��!�
X PC B
50 90 A0
50 100 300
Memory addresses
opcode n i x b p e displacement
� �.������:����������������������������������������
00 = LDA Target address = b + x + Disp = A0 + 50 + 10 = 100
Loads 300 in register A
Addressing Mode = Direct (Simple)
Target Address = 100
opcode n i x b p e displacement
� ��������:������������������������������������������
18 = ADD m Target address = b + x + Disp = A0 + 50 + 10 = 100
Adds 200 to Register A = 500
Addressing Mode = Indirect
Target Address = 100
opcode n i x b p e displacement
� �42�����:������������������������������������������
0C = STA m Target address = b + Disp = A0 + 120 = 1C0
Stores 500 from the accumulator to a memory location 1C0
Addressing Mode = Direct
Target Address = 1C0
FACULTY OF COMPUTING AND INFORMATION TECHNOLOGY
SYSTEMS PROGRAMMING CSC 2102
TEST 2
1. (a) List and explain all the activities that take place when an Assembler
language program is assembled.
• Convert mnemonic operation codes to their machine language
equivalent.
• Convert symbolic operands to their equivalent machine addresses
• Build the machine instructions in the correct format.
• Convert the data constants into their internal machine representations
• Write the object program and the assembly listing.
(b) Explain the following:
(i) SYMTAB
A table used to store addresses assigned to labels.
(ii) LOCCTR
A location counter LOCCTR is used to help in the assignment of
addresses. It is initialized to the beginning address specified in the
START statement. After each source statement is processed the length
of the assembled instruction or data area to be generated is added to
the LOCCTR
(iii) OPTAB
100 300 200
A table used to look up mnemonic operation codes and translate them
into their machine language equivalents.
2. Assume the following SIC/XE code
0050 Num1 BYTE 0100H
0100 Num2 BYTE 0050H
Explain what happens when each of the following instructions is executed. Write
machine code for each of the instructions and in each case state the addressing
mode and the format of the instruction which has been used.
(i) 0016 LDA NUM1
• Loads a number 0100H into the accumulator.
• Displacement = 0050 – 0019 = 037
opcode n i x b p e displacement
000000 1 1 0 0 1 0 0 3 7 = 032037
Machine Code = 032037
• Addressing Mode: = Simple / Direct
• Format: Format 3
(ii) 0016 LDA @Num1
• Loads a number 0050H into the accumulator.
• Displacement = 0050 – 0019 = 037
opcode n i x b p e displacement
000000 1 0 0 0 1 0 0 3 7 = 022037
Opcode = 022037
• Addressing Mode: = Indirect
• Format: Format 3
(iii) 0016 LDA #5
• Loads a base ten number 5 into the accumulator.
• Displacement = 005
opcode n i x b p e displacement
000000 0 1 0 0 0 0 0 0 5 = 010005
Machine code = 010005
• Addressing Mode: Immediate
• Format: Format 3
(iv) 0016 +LDA NUM2
• Loads the contents of address of NUM2 into the accumulator.
• Address = 00100
opcode n i x b p e address
000000 1 1 0 0 0 1 00100
Opcode = 03100100
• Addressing Mode Direct
• Format: Format 4
3. Explain what is meant by Program Relocation and use an example to show how
it is done.
Ability of loading a program anywhere in memory without stating the actual starting
address.
It is done by writing modification records e.g. for an instruction
006 +JSUB RDREC 4B101036 the modification record would be
M00000705
4. (a) How are literals different from immediate operands?
With immediate addressing the operand value is assembled as part of the
machine instruction. With a literal the assembler generates the specified value
as a constant at some other memory location. The address of this generated
constant is used as the target address for the machine instruction.
(b) Use examples to explain the difference between Absolute expressions and
Relative expressions.
An absolute expression contains only absolute terms or relative terms so long
as the relative terms occur in pairs and the terms in each pair have opposite
signs. e.g. MAXLEN EQU BUFEND – BUFFER
A relative expression is one in which all the relative terms except one can be
paired. The remaining unpaired relative term must have a positive sign e.g.
MAXLEN EQU BUFEND + 100
5 (a) Modify the SIC piece of code below by declaring the variables first so that
it can be assembled in one pass. 1000 COPY START 1000 1000 EOF BYTE C’EOF’ 454F46 1003 THREE WORD 3 000003 1006 ZERO WORD 0 000000 1009 RETADR RESW 1 100C LENGTH RESW 1 100F BUFFER RESB 4096 200F FIRST STL RETADR 141009 2012 CLOOP JSUB RDREC 480000 2015 LDA LENGTH 00100C 2018 COMP ZERO 281006 201B JEQ ENDFIL 300000 201E JSUB WRREC 480000 2021 J CLOOP 3C2012 2024 ENDFIL LDA EOF 001000 2027 STA BUFFER 0C100F 202A LDA THREE 001003 202D STA LENGTH 0C100C 2030 JSUB WRREC 482061 2033 LDL RETADR 081009 2036 RSUB 4C0000
(b) Generate the text listing for the modified code assuming a one pass
assembler that generates object code on an output device.
H^COPY ^00100^001039
T^001000^09^454F46^000003^000000
T^00200F^15^141009^480000^00100C^281006^300000^480000^3C2012
T^00201C^02^2024
T^002024^15^001000^0C100F^001003^0C100C^480000^081009^4C0000
E^00200F
MAKERERE UNIVERSITY
FACULTY OF COMPUTING & INFORMATION TECHNOLOGY
END OF SEMESTER I EXAMINATION 2006/2007
PROGRAMME: Bachelor of Science in Computer Science
YEAR OF STUDY: Year II
COURSE NAME: Systems Programming
COURSE CODE: CSC 2102
DATE: 25th January 2007 TIME: 4.00p.m.-7.00 p.m.
EXAMINATION INSTRUCTIONS
1. SECTION A IS COMPULSORY (40 MARKS)
2. ATTEMPT (03) QUESTIONS FROM SECTION B. ALL QUESTIONS CARRY
EQUAL MARKS (60 MARKS)
3. DO NOT OPEN THIS EXAM UNTIL YOU ARE TOLD TO DO SO
4. ALL ROUGH WORK SHOULD BE IN YOUR ANSWER BOOKLET.
Section A: (40 marks): All Questions are Compulsory.
1. (a) Explain briefly what you understand by Systems Programming. (2 marks)
(b) Give and briefly explain the uses of any three Systems Software. (3 marks)
2. (a) Briefly explain the uses of the following computer components:
(i) CPU (ii) Memory (iii) Memory Interfaces (4 marks)
3. Use examples to explain the difference between Direct and Indirect addressing of the
SIC/XE machine. (4 marks)
4. Explain any four directives used by the SIC/XE machine. (4 marks)
5. (a) What do you understand by Assembling a program? (1 mark)
(b) A program in Assembler language is usually assembled using two passes.
Briefly explain what is done in each pass. (5 marks)
6. Explain the following:
(i) Program Relocation (ii) A Literal Pool
(iii) A Relocation bit (iv) A bit mask (4 marks)
7. Use an example to explain what is meant by Programs with Overlay structures.
(2 marks)
8. Explain briefly the difference between a Program Block and a Control Section.
(4 marks)
9. Briefly explain the following:
(i) PROGADDR (ii) ESTAB
(iii) CSADDR iv) SEGTAB (4 marks)
10. Explain the following and give examples where possible.
(i) A Grammar (ii) Lexical Analysis (iii) Syntactic Analysis.
(3 marks)
Section B: (60 marks): Attempt only THREE questions from this section.
11. (a) Write a simple SIC/XE program that gets two integers NUM1 and NUM2
from memory, compares the two integers and adds them up if NUM1 is
greater than NUM2 or subtracts NUM1 from NUM2 if NUM1 is less than
NUM2. Store the answer in memory at a memory location RESULT.
(10 marks)
(b) Translate the first three instructions of the above program into machine
language and generate the machine listing for the written code. (10 marks)
12. Consider the code below. � � � � � � � � �
� � � � � � � � � � � � � �
� � � � � � ! " � #
� � � � � � ! " � #
� � � � � � $ % � & � � � � � �
� � � � ! & '
� � � ' �
� % � ( � ! � � � �
� � $ % � & � ) � � � �
� * % � � � � �
� � � ! � � � � � � � + � , � � � ,
� � � � � � & � � � �
� � � � �
� � � � � � � ! " � #
� � $ % � & � ) � � � �
� � � � � � "
� � - + � , � � � ,
� � � � � � � � � � ) �
� � � � ! " � # � � � ) �
� � � & � � � � � � � � � . �
� � � � & � � ! � � ( & -
� ' � / � � ! � ( & � & � � ! � 0 � & � � � �
(a) Write machine code for the instructions at addresses 0000, 0003, and 000D.
(6 marks)
(b) What does the Directive at address 1036 mean? (2 marks)
(c) Write all the Modification Records that may be needed in this piece of code.
Why don’t the other remaining instructions need Modification Records?
(8 marks)
(d) Assume that RDREC and WRREC are in different control sections and that
the variables LENGTH, BUFFER and BUFEND are referenced by these other
control sections, insert some extra lines of code in the above program to reflect
this assumption. (4 marks)
13. The program below consists of two different control sections that are to be linked
together.
(a) Write down the machine code for the instructions and directives for control
section PROGA. (5 Marks)
(d) Write down the object code (Text Listing) for PROGA as it would appear on
an output device. (5 Marks)
(e) Draw an external symbol table for this program assuming that PROGA is to be
loaded in memory from a memory location 2500 and that PROGB will
immediately follows PROGA (4 Marks)
(d) Using the assumptions made in part (c) above calculate the values for REF6
and REF7. (6 Marks)
0000 PROGA START 0 EXTDEF LISTA,ENDA EXTREF LISTB, ENDB . 0020 REF1 LDA LISTA 0023 REF2 +LDT LISTB + 4 0040 LISTA EQU * 005A REF6 WORD LISTA + LISTB 005D REF7 WORD ENDB-LISTB+ LISTA END
0000 PROGB START 0 EXTDEF LISTB,ENDB EXTREF LISTA, ENDA 0036 REF1 +LDA LISTA 003A REF2 LDT LISTB + 4 0060 LISTB EQU * 0070 ENDB EQU * 0076 REF6 WORD LISTA + LISTB 0079 REF7 WORD ENDB-LISTB+ LISTA END
14. A diagram of Overlay control sections is as shown below and the number of bytes
occupied by each control section in memory is also given.
1
2 7 4
3 8 5 6
Control Length Control
Length
Section (bytes) Section (bytes)
A 3000 F 1900
B 1800 G 400
C 4700 H 800
D 2900 X 1000
E 800 Y 800
(a) Write a series of statements that can be used to describe the above structure.
(5 Marks)
(b) Draw a segment table that will describe this structure assuming that control
section A is to be loaded from address 5000. (10 Marks)
(c) Explain the following:
(i) Overlay Manager (ii) Segment File (3 Marks)
(d) What other control sections will be needed in memory in order to run Program
Y? (2 Marks)
15. (a) Assume the PASCAL grammar and draw a top down parse tree for this
expression:
FOR I := 1 to 10 DO SUM := SUM + I (10 Marks)
A
B
C/D
E/F
G H
X
Y
(c) Use a bottom up method to parse the following statement using the operator
precedence method.
ANS := ALPHA DIV (BETA + GAMMA) – DELTA; (10 marks)
SIC/XE INSTRUCTION SET
MNEMONIC FORMAT OPCODE EFFECT Notes ADD m 3/4 18 A (A) + (m...m+2) ADDF m 3/4 58 F (F) + (m...m+5) X F ADDR r1,r2 2 90 r2 (r2) + (r1) X AND m 3/4 40 A (A) & (m…m+2) CLEAR r1 2 B4 r1 0 X COMP m 3/4 28 (A) : (m…m+2) C COMPF m 3/4 88 (F) : (m…m+5) X F COMPR r1,r2 2 A0 (r1) : (r2) X DIV m 3/4 24 A (A) / (m….m+2) DIVF m 3/4 64 F (F) / (m….m+5) X F DIVR r1,r2 2 9C r2 (r2) / (r1) X FIX 1 C4 A (F) convert to X F FLOAT 1 C0 F (A) convert to X F HIO 1 F4 Halt I/O channel number P X J m 3/4 3C PC m JEQ m 3/4 30 PC m if CC set to = JGT m 3/4 34 PC m if CC set to > JLT m 3/4 38 PC m if CC set to < JSUB m 3/4 48 L (PC); PC m LDA m 3/4 00 A (m..m+2) LDB m 3/4 68 B (m..m+2) X LDCH m 3/4 50 A [rightmost byte] LDF m 3/4 70 F (m..m+5) X F LDL m 3/4 08 L (m..m+2) LDS m 3/4 6C S (m..m+2) X LDT m 3/4 74 T (m..m+2) X LDX m 3/4 04 X (m..m+2) LPS m 3/4 D0 Load processor status from P X MUL m 3/4 20 A (A) * (m..m+2) MULF m 3/4 60 F (A) * (m..m+5) X F MULR r1,r2 2 98 r2 (r2) * (r1) X NORM 1 C8 F (F) normalised X F OR m 3/4 44 A (A) | (m..m+2) RD m 3/4 D8 A [rightmost byte] P RMO r1,r2 2 AC r2 (r1) X RSUB 3/4 4C PC (L) SHIFTL r1,n 2 A4 r1 (r1) left shift n X SHIFTR r1,n 2 A8 r1 (r1) right shift n X SIO 1 F0 Start I/O channel number P X SSK m 3/4 EC Protection key for address P X STA m 3/4 0C m..m+2 (A) STB m 3/4 78 m..m+2 (B) X STCH m 3/4 54 m (A) [rightmost STF m 3/4 80 m..m+5 (F) X F STI m 3/4 D4 Interval timer value P X STL m 3/4 14 m..m+2 (L) STS m 3/4 7C m..m+2 (S) X STSW m 3/4 E8 m..m+2 (SW) P STT m 3/4 84 m..m+2 (T) X STX m 3/4 10 m..m+2 (X) SUB m 3/4 1C A (A) - (m..m+2) SUBF m 3/4 5C F (F) - (m..m+5) X F SUBR r1,r2 2 94 r2 (r2) – (r1) X SVC n 2 B0 Generate SVC Interrupt X TD m 3/4 E0 Test Device specified by P C TIO 1 F8 Test I/O channel number P X TIX m 3/4 2C X (X) + 1; (X) : C
TIXR r1 2 B8 X (X) + 1; (X) : (r1) X C WD m 3/4 DC Device specified by (m)
(A) [rightmost byte]
P
OPERATOR PRECEDENCE TABLE
VAR BEGIN END INTEGER FOR READ WRITE TO DO ; : , := + - * DIV ( ) id int
PROGRAM = < VAR = < < < < BEGIN = < < < < < END > > INTEGER > = > < FOR READ = WRITE = TO > < < < < < < < DO < > < < < > <
; > > < < < > < < <
: > < >
, =
:= > = > < < < < < < <
+ > > > > > > < < < > < <
- > > > > > > < < < > < <
* > > > > > > > > < > < <
DIV > > > > > > > > < > < <
( > < < < < < < = < <
) > > > > > > > > >
Id > > > > > > > = > > > > >
Int > > > > > > > > >
THE PASCAL GRAMMAR
18. <prog> ::= PROGRAM <prog-name> VAR <dec-list> BEGIN <stmt-list> END
19. <prog-name>::= id
20. <dec-list> ::= <dec> | <dec-list> ; <dec>
21. <dec> ::= <id-list> : <type>
22. <type> ::= INTEGER
23. <id-list> ::= id | <id-list> , id
24. <stmt-list> ::= <stmt> | <stmt-list> ; <stmt>
25. <stmt> ::= <assign> | <read> | <write> | for
26. <assign> ::= id := <exp>
27. <exp> ::= <term> | <exp> + <term> | <exp> - <term>
28. <term> ::= <factor> | <term * <factor> | <term> DIV <factor>
29. <factor> ::= id | int | ( <exp>)
30. <read> ::= READ ( <id-list> )
31. <write> ::= WRITE ( <id-list> )
32. <for> ::= FOR <index-exp> DO <body>
33. <index-exp> ::= id := <exp> TO <exp>
34. <body> ::= <stmt> | BEGIN <stmt-list> END
MAKERERE UNIVERSITY
FACULTY OF COMPUTING & INFORMATION TECHNOLOGY
END OF SEMESTER I EXAMINATION 2006/2007
PROGRAMME: Bachelor of Science in Computer Science
YEAR OF STUDY: Year II
COURSE NAME: Systems Programming
COURSE CODE: CSC 2102
DATE: 25th January 2007 TIME: 4.00p.m.-7.00 p.m.
EXAMINATION INSTRUCTIONS
5. SECTION A IS COMPULSORY (40 MARKS)
6. ATTEMPT (03) QUESTIONS FROM SECTION B. ALL QUESTIONS CARRY
EQUAL MARKS (60 MARKS)
7. DO NOT OPEN THIS EXAM UNTIL YOU ARE TOLD TO DO SO
8. ALL ROUGH WORK SHOULD BE IN YOUR ANSWER BOOKLET.
Section A: (40 marks): All Questions are Compulsory.
1. (a) Explain briefly what you understand by Systems Programming. (2 marks)
(b) Give and briefly explain the uses of any three Systems Software. (3 marks)
2. (a) Briefly explain the uses of the following computer components:
(i) CPU (ii) Memory (iii) Memory Interfaces (4 marks)
3. Use examples to explain the difference between Direct and Indirect addressing of the
SIC/XE machine. (4 marks)
4. Explain any four directives used by the SIC/XE machine. (4 marks)
5. (a) What do you understand by Assembling a program? (1 mark)
(b) A program in Assembler language is usually assembled using two passes.
Briefly explain what is done in each pass. (5 marks)
7. Explain the following:
(i) Program Relocation (ii) A Literal Pool
(iii) A Relocation bit (iv) A bit mask (4 marks)
7. Use an example to explain what is meant by Programs with Overlay structures.
(2 marks)
8. Explain briefly the difference between a Program Block and a Control Section.
(4 marks)
10. Briefly explain the following:
(i) PROGADDR (ii) ESTAB
(iii) CSADDR iv) SEGTAB (4 marks)
11. Explain the following and give examples where possible.
(i) A Grammar (ii) Lexical Analysis (iii) Syntactic Analysis.
(3 marks)
Section B: (60 marks): Attempt only THREE questions from this section.
11. (a) Write a simple SIC/XE program that gets two integers NUM1 and NUM2
from memory, compares the two integers and adds them up if NUM1 is
greater than NUM2 or subtracts NUM1 from NUM2 if NUM1 is less than
NUM2. Store the answer in memory at a memory location RESULT.
(10 marks)
(b) Translate the first three instructions of the above program into machine
language and generate the machine listing for the written code. (10 marks)
12. Consider the code below. � � � � � � � � �
� � � � � � � � � � � � � �
� � � � � � ! " � #
� � � � � � ! " � #
� � � � � � $ % � & � � � � � �
� � � � ! & '
� � � ' �
� % � ( � ! � � � �
� � $ % � & � ) � � � �
� * % � � � � �
� � � ! � � � � � � � + � , � � � ,
� � � � � � & � � � �
� � � � �
� � � � � � � ! " � #
� � $ % � & � ) � � � �
� � � � � � "
� � - + � , � � � ,
� � � � � � � � � � ) �
� � � � ! " � # � � � ) �
� � � & � � � � � � � � � . �
� � � � & � � ! � � ( & -
� ' � / � � ! � ( & � & � � ! � 0 � & � � � �
(a) Write machine code for the instructions at addresses 0000, 0003, and 000D.
(6 marks)
(b) What does the Directive at address 1036 mean? (2 marks)
(c) Write all the Modification Records that may be needed in this piece of code.
Why don’t the other remaining instructions need Modification Records?
(8 marks)
(d) Assume that RDREC and WRREC are in different control sections and that
the variables LENGTH, BUFFER and BUFEND are referenced by these other
control sections, insert some extra lines of code in the above program to reflect
this assumption. (4 marks)
16. The program below consists of two different control sections that are to be linked
together.
(a) Write down the machine code for the instructions and directives for control
section PROGA. (5 Marks)
(f) Write down the object code (Text Listing) for PROGA as it would appear on
an output device. (5 Marks)
(g) Draw an external symbol table for this program assuming that PROGA is to be
loaded in memory from a memory location 2500 and that PROGB will
immediately follows PROGA (4 Marks)
(d) Using the assumptions made in part (c) above calculate the values for REF6
and REF7. (6 Marks)
0000 PROGA START 0 EXTDEF LISTA,ENDA EXTREF LISTB, ENDB . 0020 REF1 LDA LISTA 0023 REF2 +LDT LISTB + 4 0040 LISTA EQU * 005A REF6 WORD LISTA + LISTB 005D REF7 WORD ENDB-LISTB+ LISTA END
0000 PROGB START 0 EXTDEF LISTB,ENDB EXTREF LISTA, ENDA 0036 REF1 +LDA LISTA 003A REF2 LDT LISTB + 4 0060 LISTB EQU * 0070 ENDB EQU * 0076 REF6 WORD LISTA + LISTB 0079 REF7 WORD ENDB-LISTB+ LISTA END
17. A diagram of Overlay control sections is as shown below and the number of bytes
occupied by each control section in memory is also given.
1
2 7 4
3 8 5 6
Control Length Control
Length
Section (bytes) Section (bytes)
A 3000 F 1900
B 1800 G 400
C 4700 H 800
D 2900 X 1000
E 800 Y 800
(a) Write a series of statements that can be used to describe the above structure.
(5 Marks)
(b) Draw a segment table that will describe this structure assuming that control
section A is to be loaded from address 5000. (10 Marks)
(c) Explain the following:
(i) Overlay Manager (ii) Segment File (3 Marks)
(d) What other control sections will be needed in memory in order to run Program
Y? (2 Marks)
18. (a) Assume the PASCAL grammar and draw a top down parse tree for this
expression:
FOR I := 1 to 10 DO SUM := SUM + I (10 Marks)
A
B
C/D
E/F
G H
X
Y
(d) Use a bottom up method to parse the following statement using the operator
precedence method.
ANS := ALPHA DIV (BETA + GAMMA) – DELTA; (10 marks)
SIC/XE INSTRUCTION SET
MNEMONIC FORMAT OPCODE EFFECT Notes ADD m 3/4 18 A (A) + (m...m+2) ADDF m 3/4 58 F (F) + (m...m+5) X F ADDR r1,r2 2 90 r2 (r2) + (r1) X AND m 3/4 40 A (A) & (m…m+2) CLEAR r1 2 B4 r1 0 X COMP m 3/4 28 (A) : (m…m+2) C COMPF m 3/4 88 (F) : (m…m+5) X F COMPR r1,r2 2 A0 (r1) : (r2) X DIV m 3/4 24 A (A) / (m….m+2) DIVF m 3/4 64 F (F) / (m….m+5) X F DIVR r1,r2 2 9C r2 (r2) / (r1) X FIX 1 C4 A (F) convert to X F FLOAT 1 C0 F (A) convert to X F HIO 1 F4 Halt I/O channel number P X J m 3/4 3C PC m JEQ m 3/4 30 PC m if CC set to = JGT m 3/4 34 PC m if CC set to > JLT m 3/4 38 PC m if CC set to < JSUB m 3/4 48 L (PC); PC m LDA m 3/4 00 A (m..m+2) LDB m 3/4 68 B (m..m+2) X LDCH m 3/4 50 A [rightmost byte] LDF m 3/4 70 F (m..m+5) X F LDL m 3/4 08 L (m..m+2) LDS m 3/4 6C S (m..m+2) X LDT m 3/4 74 T (m..m+2) X LDX m 3/4 04 X (m..m+2) LPS m 3/4 D0 Load processor status from P X MUL m 3/4 20 A (A) * (m..m+2) MULF m 3/4 60 F (A) * (m..m+5) X F MULR r1,r2 2 98 r2 (r2) * (r1) X NORM 1 C8 F (F) normalised X F OR m 3/4 44 A (A) | (m..m+2) RD m 3/4 D8 A [rightmost byte] P RMO r1,r2 2 AC r2 (r1) X RSUB 3/4 4C PC (L) SHIFTL r1,n 2 A4 r1 (r1) left shift n X SHIFTR r1,n 2 A8 r1 (r1) right shift n X SIO 1 F0 Start I/O channel number P X SSK m 3/4 EC Protection key for address P X STA m 3/4 0C m..m+2 (A) STB m 3/4 78 m..m+2 (B) X STCH m 3/4 54 m (A) [rightmost STF m 3/4 80 m..m+5 (F) X F STI m 3/4 D4 Interval timer value P X STL m 3/4 14 m..m+2 (L) STS m 3/4 7C m..m+2 (S) X STSW m 3/4 E8 m..m+2 (SW) P STT m 3/4 84 m..m+2 (T) X STX m 3/4 10 m..m+2 (X) SUB m 3/4 1C A (A) - (m..m+2) SUBF m 3/4 5C F (F) - (m..m+5) X F SUBR r1,r2 2 94 r2 (r2) – (r1) X SVC n 2 B0 Generate SVC Interrupt X TD m 3/4 E0 Test Device specified by P C TIO 1 F8 Test I/O channel number P X TIX m 3/4 2C X (X) + 1; (X) : C
TIXR r1 2 B8 X (X) + 1; (X) : (r1) X C WD m 3/4 DC Device specified by (m)
(A) [rightmost byte]
P
OPERATOR PRECEDENCE TABLE
VAR BEGIN END INTEGER FOR READ WRITE TO DO ; : , := + - * DIV ( ) id int
PROGRAM = < VAR = < < < < BEGIN = < < < < < END > > INTEGER > = > < FOR READ = WRITE = TO > < < < < < < < DO < > < < < > <
; > > < < < > < < <
: > < >
, =
:= > = > < < < < < < <
+ > > > > > > < < < > < <
- > > > > > > < < < > < <
* > > > > > > > > < > < <
DIV > > > > > > > > < > < <
( > < < < < < < = < <
) > > > > > > > > >
Id > > > > > > > = > > > > >
Int > > > > > > > > >
THE PASCAL GRAMMAR
35. <prog> ::= PROGRAM <prog-name> VAR <dec-list> BEGIN <stmt-list> END
36. <prog-name>::= id
37. <dec-list> ::= <dec> | <dec-list> ; <dec>
38. <dec> ::= <id-list> : <type>
39. <type> ::= INTEGER
40. <id-list> ::= id | <id-list> , id
41. <stmt-list> ::= <stmt> | <stmt-list> ; <stmt>
42. <stmt> ::= <assign> | <read> | <write> | for
43. <assign> ::= id := <exp>
44. <exp> ::= <term> | <exp> + <term> | <exp> - <term>
45. <term> ::= <factor> | <term * <factor> | <term> DIV <factor>
46. <factor> ::= id | int | ( <exp>)
47. <read> ::= READ ( <id-list> )
48. <write> ::= WRITE ( <id-list> )
49. <for> ::= FOR <index-exp> DO <body>
50. <index-exp> ::= id := <exp> TO <exp>
51. <body> ::= <stmt> | BEGIN <stmt-list> END
MAKERERE UNIVERSITY
FACULTY OF COMPUTING & INFORMATION TECHNOLOGY
END OF SEMESTER I EXAMINATION 2007/2008
PROGRAMME: Bachelor of Science in Computer Science
YEAR OF STUDY: Year II
COURSE NAME: Systems Programming
COURSE CODE: CSC 2102
DATE: 4th December 2007 TIME: 4.00p.m.-7.00 p.m.
EXAMINATION INSTRUCTIONS
9. SECTION A IS COMPULSORY (40 MARKS)
10. ATTEMPT (03) QUESTIONS FROM SECTION B. ALL QUESTIONS CARRY
EQUAL MARKS (60 MARKS)
11. DO NOT OPEN THIS EXAM UNTIL YOU ARE TOLD TO DO SO
12. ALL ROUGH WORK SHOULD BE IN YOUR ANSWER BOOKLET.
Section A: (40 marks): All Questions are Compulsory.
1. (a) Give and briefly explain the uses of any three Systems Software.
• Compilers translate high level programs into machine code.
• Assemblers translate Assembler Language into machine code.
• Loaders they prepare machine language programs for execution
• Macro processors allow programmers to use abbreviations
• Operating Systems and file systems allow flexible storing and retrieval of
information. (3 marks)
(b) How does Systems Software differ from Application Software?
Application programs are written by the user for the purpose of solving
particular User problems using a computer as a tool whereas the Systems
Software is to make more effective use of the computer. (1 mark)
2. Explain briefly:
(i) The Format of a machine language instruction.
It is the arrangement of an instruction with respect to assigning meaning to its
various groups of bits. It consists of the Operation Code which is a portion
that specifies what the instruction does and the Operand which is any piece of
data or address that is required by the instruction to complete its execution.
(2 marks)
(ii) The Format of an Assembler Language instruction.
Label: Mnemonic Operand, Operand, ; remarks
Label: It is a symbol assigned to the address of the first byte of the instruction
in which it appears.
A mnemonic is the abbreviation for the real instruction.
The Operand(s) is the data or the address needed to complete the instruction.
Remarks are for documenting the program. (2
marks)
3. Use examples to help you explain any 3 addressing modes for the Intel 8085
microprocessor.
(Any 3 of the following)
• Immediate Addressing: Information is part of the instruction
• Direct addressing: The address is part of the instruction.
• Register addressing: The operand is in the register and the register’s address is part
of the instruction.
• Indirect Addressing: The address is in the location whose address is specified as part
of the instruction.
• Base addressing: The address is formed by adding the contents of a memory location
or register to a number called a displacement which is part of the instruction.
• Indexing: It is a process of incrementing or decrementing an address as the computer
sequences through a set of consecutive or evenly spaced addresses. (6 marks)
4. Consider the following INTEL 8085 Assembler Code.
0045 NUM: DB 10, 20, 30 3020 MAK: DB 50, 60
(a) Explain what each of the following instruction does and give the contents
of the registers involved in each case.
(i) LDA NUM
Loads contents of the address NUM into the accumulator; A = 10
(2 marks)
(ii) LHLD NUM+1
Loads contents of NUM+1 and NUM+2 into the register pair HL
H = 30 L = 20 (2 marks)
(iii) LXI D, NUM + 1
Loads register pair DE with the address of NUM + 1
D = 00 E = 46 (2 marks)
(b) Assume that each of the instructions in part (a) above were executed and
explain what each of the following instruction does and the contents of the
registers involved in each case.
(i) INX D
Increment register pair DE; i.e. D = 00; E = 47 (2 marks)
(ii) INR M
Increment contents of a memory location whose address is in the
register pair H.L i.e. M = 51 (2 marks)
(iii) LDAX D
Load the Accumulator with contents of a memory location whose
address is in the DE register pair; A = 30 (2 marks)
13. Give the Mnemonics of any five registers found in the SIX/XE and state their
uses.
(Any 5 of the following) A Accumulator; used for arithmetic Operations
X Index register; used for addressing
L Linkage register; the Jump to subroutine (JSUB) instruction stores the return
address in this register.
PC Program Counter; Contains the address of the next instruction to be fetched
for execution.
SW Status word; contains the condition codes
B Base register, used for addressing
S General Working register, no special use.
T General Working register, no special use.
F Floating Point Accumulator. (5 marks)
6. Assume the following code for the SIC machine. The Operation Code for the
Mnemonic STL is 14
0022 STL Buffer, X 2020 Buffer: RESW 1
Derive machine code for the instruction at address 0022.
6 1 1 1 1 1 1 20
0001 01 1 1 1 0 0 1 02020 = 17B02020 (2 marks)
opcode n i x b p e address
7. (i) What is program relocation?
Ability of a program to be able to run successfully in memory without
considering the address where it is going to be loaded. (2 marks)
(ii) Explain why some instruction need modification records during program
relocation and others do not.
Instruction that have been assembled using addresses are the ones that need to
be modified; format 1, format 2 do need have address operands; and format 3
instructions that have been assembled using program counter relative or base
relative are similarly not affected because the displacements do not change
when the program is loaded. (2 marks)
8. Explain the following:
(i) PROGADDR
The beginning address in memory where the linked program is loaded.
(1 marks)
(ii) ESTAB
External symbol used to store names and addresses of each external symbol in
the set of control sections being loaded. It also indicates in which control
section the symbol is defined. (1 marks)
(iii) CSADDR
The starting address assigned to the control section currently being scanned
by the loader. (1 marks)
Section B: (60 marks): Attempt only THREE questions from this section.
9. (a) Briefly explain the uses of the components of the of the Control Unit of a
typical microprocessor.
• The Program Counter (PC) :It holds the address of the main memory
location from which the next instruction is to be fetched.
• Instruction Register (IR) Receives the instruction when it is brought from
memory and holds it while it gets decoded and executed.
• Processor Status Word (PSW) contains condition flags which indicate the
current status of the CPU and the important characteristics of the result of
the previous instruction.
• Stack Pointer (SP): Accesses a special part of memory called a stack. It is
used to temporarily store important information while sub routines are
being executed. It hold the address at the top of the stack. (8 marks)
(b) (i) What is an interface
Circuitry needed to connect the bus to a device. (1 mark)
(ii) Give the functions of the I/O interface
• Buffer data onto/off the system bus
• Receive commands from the CPU
• Transmit information from their devices to the CPU (3 marks)
(iii) Give the functions of the memory interface.
• Needed to decode the address of the memory location being
accessed.
• Buffer data onto/off the bus.
• Contain circuitry to perform memory reads or write (3 marks)
(c) Give and explain the components of the Processor Status Word for the
Intel 8085 microprocessor.
The PSW for the Intel 8085 has 5 flags.
• Zero (Z): set when the result of the operation is zero.
• Sign (S): set when sign of the result is negative.
• Parity (P): When the parity of the bits in the result is even.
• Carry (C): Addition resulted into a carry or subtraction or comparison
resulted into a borrow.
• Auxiliary Carry (AC) Carry in BCD arithmetic. (5 marks)
10. (a) An array MYARRY contains 10 integers (negative and positive). Write an
Intel 8085 Assembler language program that will add up all the integers
of this array and store the answer at a memory location GREATER if the
answer is greater than 100 or at a memory location LESS if the answer is
less than 100.
MVI D, 10
LXI H, MYARRAY
S Z AC P C
MOV A, M
LOOP: INX H
ADD M
DCR D
JNZ LOOP
CPI 100
JP MORE
STA LESS
JMP OUT
MORE: STA GREATER
MYARRAY DS 10
GREATER: DS 1
LESS DS 1
(10 Marks)
(b) Write an equivalent program for the same problem using the SIC/XE
machine code.
LDS #100
LDT # 10
LDA #0
LDX #1
AGAIN: ADD MYARRAY, X
TIXR T
JLT AGAIN
COMPR A, S
JLT SMALL
STA GREATER
J OUT
SMALL: STA LESS
OUT:
MYARRAY: RESW 10
GREATER: RESW 1
LESS: RESW 1 (10 Marks)
11. Given below is a SIC/XE program PROG.
LDS # 10
LDA #0
LDX #1
AGAIN: ADD ALPHA, X
TIXR S
JLT AGAIN
STA RESULT
ALPHA: RESW 10
RESULT: RESW 1
(iv) Study the program carefully and explain briefly what is being
accomplished.
The program adds up 10 integers in an array ALPHA and stores the answer at
a memory location RESULT (3 Marks)
(v) Assuming that it is to be loaded in memory from 0058H, generate the
corresponding addresses for each instruction and write the corresponding
machine code using the operation code table below.
Mnemonic Opcode
LDS 6C
LDA 00
LDX 04
ADD 18
TIXR B8
STA 0C
JLT 38
S 4
0058 LDS #10 6D000A
005B LDA #0 010000
005E LDX #1 050001
0061 AGAIN: ADD ALPHA,X 1BA008
0064 TIXR S B840
0066 JLT AGAIN 3B2FF8
0069 STA RESULT 0F201E
006C ALPHA RESW 10
008A RESULT RESW 1
(17 Marks)
12. (a) Two passes are usually used to translate an Assembler Language program to machine code; explain briefly what is accomplished in each
pass and state the tables and variables used in each pass.
• Pass 1 (Define symbols)
• Scans the source program for label definitions using the LOCATION
COUNTER and assigns addresses to all statements in the program.
• Saves the addresses assigned to all labels for use in pass 2 in the
SYMBOL TABLE
• Perform some processing of the assembler directives.
• Pass 2 (assemble the instructions and generate machine code)
• Assembles the instruction using the Symbol Table (SYMTAB) and the
operations Code Table (OPTAB).
• Generate data values defined by BYTE, WORD, etc.
• Perform processing of the directives not done during pass 1.
• Write the object program and assembly listing onto some output device
which will later be loaded in memory for execution. (5 marks)
(c) Consider the code given below.
0000 EXAM START 0
0000 FIRST STL RETAD 17202D
0003 LDB #LENG 69202D
BASE LENGT
0006 CLOOP +JSUB RDREC 4B10103
000A LDA LENGT 032026
000D COMP #0 290000
0010 JEQ ENDFIL 332007
0013 +JSUB WRREC 4B10105
0017 J CLOOP 3F2FEC
001A ENDFIL LDA EOF 032010
001D STA BUFFE 0F2016
0020 LDA #3 010003
0023 STA LENGT 0F200D
0026 +JSUB WRREC 4B10105
002A J @RETA 3E2003
002D EOF BYTE C’EOF’ 454F46
0030 RETAD RESW 1
0033 LENGT RESW 1
0036 BUFFE RESB 4096
(i) Some instructions in the code above will change when the program
is loaded in memory from a different memory location other than
0000. Give the addresses of the instructions which will change and
explain why the others will not change.
Instructions at addresses 0006, 0013 and 0026 will change. The others
will not change because their machine codes do not contain addresses.
(3 marks)
(i) Generate the object code for the program above. H^ EXAM ^000000^ 001036
T^000000^1D^17202D^69202D^4B101036^032026^290000^332007^4B10105D^3F2FEC^032010
T^000001D^13^0F2016^010003^0F200D^4B10105D^3E2003^454F46
M^000007^05
M^000014^05
M^000027^05
E^000000 (12 marks)
13. Consider the program code below written in the simple SIC format.
(a) Modify the program so that it can be assembled in one pass. (10 marks)
1000 EXAM START 1000
1000 INDEX RESW 1
1003 ALPHA RESW 4
100F BETA RESW 4
101B GAMMA RESW 4
1027 THREE WORD 3 000003
102A ZERO WORD 0 000000
102D K300 WORD 12 00012C
1030 LDA ZERO 00102A
1033 STA INDEX 0C1000
1036 LOOP LDX INDEX 041000
1039 LDA ALPHA,X 009003
103C ADD BETA,X 18900F
103F STA GAMMA,X 0C901B
1042 LDA INDEX 001000
1045 ADD THREE 181027
1048 STA INDEX 0C1000
104B COMP K300 28102D
104E JLT LOOP 381036
(10 marks)
(b) Use the Load and Go method to show how the above program will appear
in memory.
1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 100A 100B 100C 100D 100E 100F
1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 101A 101B 101C 101D 101E 101F
00 00 03 00 00 00 00 01 2C
1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 102A 102B 102C 102D 102E 102F
00 10 2A 0C 10 00 04 10 00 00 90 03 18 90 0F 0C
1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 103A 103B 103C 103D 103E 103F
90 1B 00 10 00 18 10 27 0C 10 00 28 10 2D 38 10
1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 104A 104B 104C 104D 104E 104F
36
1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 105A 105B 105C 105D 105E 105F
(6 marks)
(c) Explain the following
(i) Programs with Overlay Structures.
They are programs that are designed to execute in such a way that if
both or all of them are not needed in memory at the same time, one
can execute first and the other will execute in the same memory space
after the first one has been executed. (2 marks)
(ii) The meaning of the expression: MYNUM EQU * The current value of the location counter is assigned to the variable
MYNUM (2 marks)
14. (a) (i) Briefly explain the difference between Program Blocks and
Control Sections.
Control sections differ from program blocks in that they are handled
separately by the assembler. It is not necessary for all control sections
in a program to be assembled at the same time. Each control section is
independent of another whereas Program Blocks are sections of code
re-arranged in the same unit. (2 marks)
(ii) What are the directives used to indicate a new Program Block and
a new Control section respectively in a program?
The directive USE indicates a new Program Block while the Directive
CSECT announces a new Control Section. (2 marks)
(b) Assume that the following piece of code is in a program block called
PROGA.
001C LDT NUM
002C Number: RESB 1
(i) If the beginning address of PROGA is 000A and the code at
address 002C is the last directive in PROG A, what is the length of
Program Block PROGA?
002D – 000A = 0023 (2 marks)
(ii) Assume that NUM is defined at address 000E in the next Program
Block PROGB which begins at address 0000H. If the Operation
Code for the instruction LDT is 74, derive the machine instruction
for the Assembler instruction at address 001C in PROGA.
The displacement = 002D – 001F + 000E = 01C
6 1 1 1 1 1 1 12
0111 0111 0010 01C = 77201C (4 marks)
(c) Explain any 5 Loader Options that can be used to modify the standard
processing of a program.
• INCLUDE: Allows the selection of alternative sources of input.
• DELETE Allows the user to delete external symbols or entire control
section.
• CHANGE: To change external symbols
• LIBRARY: Specifies alternative libraries to be searched.
• NOCALL: To exclude some functions that come with the library search
• Options to control outputs from the loader. The user can specify whether
an output is needed or not.
opcode n i x b p e disp
• Options to specify whether external references will be resolved by
library search.
• An option to specify the location at which execution is to begin thus
overriding any information given in the object program.
• An option to control whether or not the loader should attempt to execute
the program if errors are detected during the load. (10 marks)
15. Given below are two control sections PROG1 and PROG2 both loaded in
memory.
(a) Give the operands for the Directives EXTREF and EXTDEF in each
control section.
Prog1 Prog2
EXDEF NUM1 EXDEF STORE2
EXTREF STORE2 EXTREF NUM1 (2 marks)
(b) Derive machine code for the instructions at addresses 0020, 0027, 0060 in
PROG1 and 0036, 003D and 007C in PROG2 assuming that the operation
codes for the instructions LDT and STT are 74 and 84 respectively.
AT 0020: The displacement = 0040 – 23 = 01D
6 1 1 1 1 1 1 12
0111 0111 0010 01D = 77201D (1 mark)
AT 0027: The target address is not known; we use format 4
6 1 1 1 1 1 1 20
1000 0111 0001 00000 = 87100000 (1 mark)
AT 0060: 0000 – 0040 = -000040 = FFFFC0 (1 mark)
AT 0036: NUM is not known, format 4 is used
0111 0111 0001 00000 = 77100000 (1 mark)
AT 003D Displacement = 0060 – 0040 = 020
1000 1011 0010 020 = 872020 (1 mark)
AT 007C: 000060 – 000000 = 000060 (1 mark)
(c) Write the object code for the two Control Sections.
H^PROG1 ^000000^000063
opcode n i x b p e disp
opcode n i x b p e address
D^NUM1 ^000040
R^STORE2
T^000020^0B^77201D ^8710000
T^000060^03^FFFFC0
M^000028^05^+STORE2
M^000060^06^+STORE2
M^000060^06^-PROG1
E^000020 (4 marks)
H^PROG2 ^000000^00007F
D^STORE2 ^000060
R^NUM1
T^000036^0A^77100000^872020
T^00007C^03^000060
M^000037^05^+NUM1
M^00007C^06^+PROG2
M^00007C^06^-NUM1
E (4 marks)
(d) Assume that the first control section PROG1 is loaded in memory at
address 1200 and that PROG2 is loaded immediately after PROG1,
calculate the value of RESULT
( 001200 + 63 + 60) – (001200 + 40) = 000083 (4 marks)
0000
PROG1 START 0
EXTDEF
EXTREF
.
0020 LDT NUM1 77201D
0027 +STT STORE2 8710000
0
0040 NUM1 RESW 1
0060 RESULT WORD STORE2 –
NUM1
FFFFC0
END
0000 PROG2 START 0
EXTDEF
EXTREF
.
0036 +LDT NUM1 77100000
003D STT STORE2 872020
0060 STORE2 RESW 1
007C RESULT WORD STORE2 -
NUM1
000060
END
MAKERERE UNIVERSITY
FACULTY OF COMPUTING & INFORMATION TECHNOLOGY
END OF SEMESTER I EXAMINATION 2007/2008
PROGRAMME: Bachelor of Science in Computer Science
YEAR OF STUDY: Year II
COURSE NAME: Systems Programming
COURSE CODE: CSC 2102
DATE: 4th December 2007 TIME: 4.00p.m.-7.00 p.m.
EXAMINATION INSTRUCTIONS
14. SECTION A IS COMPULSORY (40 MARKS)
15. ATTEMPT (03) QUESTIONS FROM SECTION B. ALL QUESTIONS CARRY
EQUAL MARKS (60 MARKS)
16. DO NOT OPEN THIS EXAM UNTIL YOU ARE TOLD TO DO SO
17. ALL ROUGH WORK SHOULD BE IN YOUR ANSWER BOOKLET.
Section A: (40 marks): All Questions are Compulsory.
1. (a) Give and briefly explain the uses of any three Systems Software. (3 marks)
(b) How does Systems Software differ from Application Software? (1 mark)
2. Explain briefly:
(i) The Format of a Machine Language instruction. (2 marks)
(ii) The Format of an Assembler Language instruction. (2 marks)
3. Use examples to help you explain any 3 addressing modes for the Intel 8085
microprocessor. (6 marks)
4. Consider the following INTEL 8085 Assembler Code.
0045 NUM: DB 10, 20, 30 3020 MAK: DB 50, 60
(a) Explain what each of the following instruction does and give the contents of
the registers involved in each case.
(i) LDA NUM (ii) LHLD NUM+1 (iii) LXI D, NUM + 1 (6 marks)
(b) Assume that each of the instructions in part (a) above were executed and
explain what each of the following instructions does and the contents of the
registers involved in each case.
(i) INX D (ii) INR M (iii) LDAX D (6 marks)
5. Give the Mnemonics (abbreviations) of any five registers found in the SIX/XE and
state their uses. (5 marks)
6. Assume the following code for the SIC machine. The Operation Code for the
Mnemonic STL is 14
0022 STL Buffer, X 2020 Buffer RESW 1
Derive machine code for the instruction at address 0022. (2 marks)
7. (i) What is program relocation? (2 marks)
(ii) Explain why some instruction need modification records during program
relocation and others do not. (2 marks)
8. Explain the following:
(i) PROGADDR (ii) ESTAB (iii) CSADDR (3 marks)
Section B: (60 marks): Attempt only THREE questions from this section.
9. (a) Briefly explain the uses of the components of the of the Control Unit of a
typical microprocessor. (8 marks)
(b) (i) What is an interface (1 mark)
(ii) Give the functions of the I/O interface (3 marks)
(iii) Give the functions of the memory interface. (3 marks)
(c) Give and explain the components of the Processor Status Word for the Intel
8085 microprocessor. (5 marks)
10. (a) An array MYARRY contains 10 integers (negative and positive). Write an
Intel 8085 Assembler language program that will add up all the integers of this
array and store the answer at a memory location GREATER if the answer is
greater than 100 or at a memory location LESS if the answer is less than 100.
(10 Marks)
(b) Write an equivalent program using the SIC/XE machine code for the same
problem. (10 Marks)
11. Given below is a SIC/XE program PROG.
LDS # 10 LDA #0 LDX #1 AGAIN: ADD ALPHA, X TIXR S JLT AGAIN STA RESULT ALPHA: RESW 10 RESULT: RESW 1
(vi) Study the program carefully and explain briefly what is being accomplished.
(3 Marks)
(vii) Assuming that it is to be loaded in memory from 0058H, generate the
corresponding addresses for each instruction and write the corresponding
machine code using the operation code table below. (17 Marks)
Mnemonic Opcode
LDS 6C
LDA 00
LDX 04
ADD 18
TIXR B8
STA 0C
JLT 38
S 4
12. (a) Two passes are usually needed to translate an Assembler language program to
machine code; explain briefly what is accomplished in each pass and state the
tables and the variables used in each pass. (5 marks)
(d) Consider the code given below.
000 EXAM START 0
000 FIRST STL RETA 17202000 LDB #LENG 69202 BASE LENGT 000 CLOOP +JSUB RDRE 4B101000 LDA LENGT 03202000 COMP #0 29000001 JEQ ENDFI 33200001 +JSUB WRRE 4B101001 J CLOOP 3F2FE001 ENDFI LDA EOF 03201001 STA BUFFE 0F201002 LDA #3 01000002 STA LENGT 0F200002 +JSUB WRRE 4B101002 J @RET 3E200002 EOF BYTE C’EOF’ 454F4003 RETA RESW 1 003 LENGT RESW 1 003 BUFFE RESB 4096
(j) Some instructions in the code above will change when the program is
loaded in memory from a different memory location other than 0000.
Give the addresses of the instructions which will change and explain
why the others will not change. (3 marks)
(i) Generate the object code for the program above. (12 marks)
13. Consider the program code below written in the simple SIC format.
(a) Modify the program so that it can be assembled in one pass. (10 marks)
1000 EXAM START 1000
1000 LDA ZERO 00104B
1003 STA INDEX 0C1021
1006 LOOP LDX INDEX 041021
1009 LDA ALPHA,X 009024
100C ADD BETA,X 189030
100F STA GAMMA,X 0C903C
1012 LDA INDEX 001021
1015 ADD THREE 181048
1018 STA INDEX 0C1021
101B COMP K300 28104E
101E JLT LOOP 381006
1021 INDEX RESW 1
1024 ALPHA RESW 4
1030 BETA RESW 4
103C GAMMA RESW 4
1048 THREE WORD 3 000003
104B ZERO WORD 0 000000
104E K300 WORD 12 00000C
(b) Use the Load and Go method to show how the above program will appear in
memory. (6 marks)
(c) Explain the following
(i) Programs with Overlay Structures. (2 marks)
(ii) The meaning of the expression: MYNUM EQU * (2 marks)
14. (a) (i) Briefly explain the difference between Program Blocks and Control
Sections. (2 marks)
(ii) What are the directives used to indicate a new Program Block and a
new Control section respectively in a program (2 marks)
(b) Assume that the following piece of code is in a program block called PROGA.
001C LDT NUM 002C NUMBER: RESB 1
(iii) If the beginning address of PROGA is 000A and the code at address
002C is the last directive in PROG A, what is the length of Program
Block PROGA? (2 marks)
(iv) Assume that NUM is defined at address 000E in the next Program
Block PROGB which begins at address 0000H. If the Operation Code
for the instruction LDT is 74, derive the machine instruction for the
Assembler instruction at address 001C in PROGA. (4 marks)
(ci) Explain any 5 Loader Options that can be used to modify the standard
processing of a program. (10 marks)
15. Given below are two control sections PROG1 and PROG2 both loaded in memory.
0000
PROG1 START 0
EXTDEF
EXTREF
0020
LDT NUM1
0027
+STT STORE2
0040
NUM1 RESW 1
0060
RESULT
WORD STORE2 –NUM1
END
0000 PROG2 START 0
EXTDEF
EXTREF
.
0036 +LDT NUM1
003D STT STORE2
0060 STORE2 RESW 1
007C RESULT WORD STORE2 - NUM1
END (a) Give the operands for the Directives EXTREF and EXTDEF in each control
section. (2 marks)
(b) Derive machine code for the instructions at addresses 0020, 0027, 0060 in
PROG1 and 0036, 003D and 007C in PROG2 assuming that the operation
codes for the instructions LDT and STT are 74 and 84 respectively. (6 marks)
(e) Write the object code for the two Control Sections. (8 marks)
(f) Assume that the first control section PROG1 is loaded in memory at address
1200 and that PROG2 is loaded immediately after PROG1, calculate the value
of RESULT (4 marks)
FACULTY OF COMPUTING AND INFORMATION TECHNOLOGY
SYSTEMS PROGRAMMING CSC 2102
TEST 2
1. Explain the following terms used in Systems Programs:
(i) Assembling
To produce machine language instructions from assembler language along
with information for the loader.
(ii) Loading
Bring the object program into memory for execution.
(iii) Program Relocation
Modifies the object program so that it can be loaded at an address different
from the location originally specified
(iv) Linking
Combines two or more separate object programs and supply the information
needed to allow references between them
(v) Literal Table
A table containing information about the literals. It contains the literal name,
the operand value and the address assigned to the operand when it is placed
in the literal pool
(vi) Literal Origin
It is a directive used to create a literal pool that contains all the literal
operands used since the previous LTORG or the beginning of the program.
2. Briefly explain one of the methods that may be used to assemble a program in
one pass.
One type produces object code directly in memory for immediate execution. No object
code is written out and no loader is needed (load and go). In both cases data item
definitions are put at the top of the program.
The other method produces the usual kind of object program for later execution.
Forward references are entered into lists as before but when the definition of the
symbol is encountered another text record with the correct operand address is
generated. When the program is loaded, this address will be inserted into the
instruction by the action of the loader.
6. Use examples where possible to help you briefly explain the difference between
the following:
��� Program Blocks and Control Sections
A control Section is part of the program that maintains its identity after
assembly; each section can be loaded and relocated independently of each
other. Different control sections are most often used for subroutines or other
logical subdivisions of a program.
Control sections use External References to connect each other.
Program Blocks are segments of code that are re-arranged within a single
object unit.
The assembler rearranges these segments to gather together the pieces of each
block. These blocks are then assigned addresses in the object program with
the blocks appearing in the same order in which they were first began in the
source program.
During pass 1 a separate location counter is maintained for each block. It is
initialized to 0 when the block is first began. At the end of pass 1 the latest
value of the location counter for each block indicates the length of that block.
Control sections differ from program blocks in that they are handled
separately by the assembler
(b) EXTDEFS and EXTREFS
The EXTDEF statement names external that are defined in the current control
section but may also be used by other sections. The EXTREF statement names
symbols used in the current control section but are defined elsewhere.
(c) Absolute expressions and Relative expressions.
An expression that contains only absolute terms (independent of the program
location like constants) is an absolute expression. It may also contain relative
terms so long as the relative terms occur in pairs and the terms in each pair
have opposite signs.
A relative expression is one in which all the relative terms except one can be
paired. The remaining unpaired relative term must have a positive sign.
(d) Literals and immediate operands
A literal is a constant operand whose value is written as part of the instruction
that uses it. The assembler generates the specified value as a constant at some
other memory location. The address of this generated constant is used as the
target address for the machine instruction. An immediate operand is
assembled as part of the machine instruction.
5. Consider the code below
� � � � � � � � �
� � � � � � � � � � � � � �
� � � � � � ! " � #
� � � � � � ! " � #
� � � � � � $ % � & � � � � � �
� � � � ! & '
� � � ' �
� % � ( � ! � � � �
� � $ % � & � ) � � � �
� * % � � � � �
� � � ! � � � � � � � + � , � � � ,
� � � � � � & � � � �
� � � � �
� � � � � � � ! " � #
� � $ % � & � ) � � � �
� � � � � � "
� � - + � , � � � ,
� � � � � � � � � � ) �
� � � � ! " � # � � � ) �
� � � & � � � � � � � � � . �
� � � � & � � ! � � ( & -
� ' � / � � ! � ( & � & � � ! � 0 � & � � � �
a. (i) The Operations codes for the instructions STL, LDB, and COMP
are 14, 68, and 28 respectively, write machine code for the
instructions at addresses 0000, 0003, and 000D.
STL RETADR
Displacement = 0030 – 0003 = 02D
Format = opcode n i x b p e displacement
= 000101 1 1 0 0 1 0 02D = 17202D
LDB #LENGTH
Displacement = 0033 – 0006 = 02D
Format = opcode n i x b p e displacement
= 011010 1 0 1 0 1 0 02D = 69202D
COMP #0
Displacement = 000
Format = opcode n i x b p e displacement
= 001010 0 1 0 0 0 0 000 = 290000
(ii) What does the Directive at address 1036 mean?
It gives BUFEND the value of the address of the next byte after the
buffer area = 1036
b. Write all the Modification Records that may be needed in this piece of
code. Why don’t the other remaining instructions need Modification
Records?
M^000007^05
M^000014^05
M^000027^05
The other instructions in the program do not need to be modified because in
some cases the operand is not memory or the operand is specified using
program counter relative addressing or base relative addressing.
c. Assume that RDREC and WRREC are in different control sections and
that the variables LENGTH, BUFFER and BUFEND are referenced by
these other control sections:
(i) Insert some extra lines of code in the above program to reflect this
assumption.
These lines are inserted in the program after the first line.
EXTDEF BUFFER, BUFEND, LENGTH
EXTREF RDREC, WRREC
(ii) Write the machine code for the instructions at addresses 0006,
0013 and 0026. The Operation code for the instruction JSUB is 48.
Address = 00000
Format = opcode n i x b p e address
= 010010 1 1 0 0 0 1 00000 = 4B100000
d. Assume that the instruction at address 000A is in a block whose length is
003F and that the operand NUM is at address 0006 of the next block.
Derive the machine code for this instruction.
Effective address = 003F + 0006 = 0045
Displacement = 0045 – 000D = 038
Format = opcode n i x b p e displacement
= 0000 00 1 1 0 0 1 0 038 = 0312038