System Software QB ANSWERS
System Software QB ANSWERS
System Software QB ANSWERS
2) Write a SIC/XE program to read 100 byte record from a device ‘F5’ into
BUFFER. Use immediate and register-to-register instructions.
3.) Bring out differences between system software and application software, with
examples.
4.) Suppose that RECORD contains a 100 byte record. Write a subroutine for
SIC/XE that will write this record onto the device F1. Use immediate and
register-toregister instructions as efficient as possible.
COMPARE TO 100
JLT WLOOP LOOP IF LESS THAN 100
.
.
.
OUTDEV BYTE X’F1’ OUTPUT DEVICE NUMBER
RECORD RESB 100 100 BYTE BUFFER
5.) Write a SIC/XE program to copy array A of 100 words to array B of same
size.
6.) Write sequence of instruction for SIC to clear 20 byte strings to all blanks.
ANSWER:
LDX ZERO
STCH STR1,X
TIX TWENTY
JLT LOOP
STR RESW 20
BLANK BYTE C’ ‘
ZERO WORD 0
TEWNTY WORD 20
8.) Write a program in both SIC to copy a character string ‘system software’
to another string .
ANSWER:
LDX ZERO INITIALIZE INDEX TO ZERO
STR2
9.) Explain SIX/XERESB 15 architecture
machine 15 BYTE VARIABLE
FIFTEEN WORD 15
9.) Explain SIX/XE machine architecture
ANSWER:
b) 010030
ANSWER:
a.)032600
0000 0011 0010 0110 0000 0000
Opcode n I x b p e displacement
0 3 2 6 0 0
TA=disp+(pc) Explain SIC Mach
=0110 0000 0000 +(PC)
=600+003000
=3600
• Location Counter(LOCCTR)
the operation Code Table (OPTAB) and the Symbol Table (SYMTAB).
OPTAB: It is used to lookup mnemonic operation codes and translates them to their
machine language equivalents. In more complex assemblers the table also contains
Explain SIC Mach
information about instruction format and length. In pass 1 the OPTAB is used to look up
and validate the operation code in the source program. In pass 2, it is used to translate the
operation codes to machine language. In simple SIC machine this process can be
performed in either in pass 1 or in pass 2. But for machine like SIC/XE that has instructions
of different lengths, we must search OPTAB in the first pass to find the instruction length for
incrementing LOCCTR. In pass 2 we take the information from OPTAB to tell us which
instruction format to use in assembling the instruction, and any peculiarities of the object
code instruction.
OPTAB is usually organized as a hash table, with mnemonic operation code as the key. The
A
hash table organization is particularly appropriate, since it provides fast retrieval with a
minimum of searching. Most of the cases the OPTAB is a static table- that is, entries are not
normally added to or deleted from it. In such cases it is possible to design a special hashing
function or other data structure to give optimum performance for the particular set of keys
being stored.
SYMTAB: This table includes the name and value for each label in the source program,
together with flags to indicate the error conditions (e.g., if a symbol is defined in two
different places).
During Pass 1: labels are entered into the symbol table along with their assigned address
value as they are encountered. All the symbols address value should get resolved at the
pass 1.
During Pass 2: Symbols used as operands are looked up the symbol table to obtain the
address value to be inserted in the assembled instructions.
SYMTAB is usually organized as a hash table for efficiency of insertion and retrieval. Since
entries are rarely deleted, efficiency of deletion is the important criteria for optimization.
Both pass 1 and pass 2 require reading the source program. Apart from this an intermediate
file is created by pass 1 that contains each source statement together with its assigned
address, error indicators, etc. This file is one of the inputs to the pass 2. A copy of the source
program is also an input to the pass 2, which is used to retain the operations that may be
performed during pass 1 (such as scanning the operation field for symbols and addressing
flags), so that these need not be performed during pass 2. Similarly, pointers into OPTAB
and SYMTAB is retained for each operation code and symbol used. This avoids need to
repeat many of the table-searching operations.
Explain SIC Mach
LOCCTR: Apart from the SYMTAB and OPTAB, this is another important variable which
helps in the assignment of the addresses. LOCCTR is initialized to the beginning address
mentioned in the START statement of the program. After each statement is processed, the
length of the assembled instruction is added to the LOCCTR to make it point to the next
instruction. Whenever a label is encountered in an instruction the LOCCTR value gives the
address to be associated with that label.
3.) Define program relocation. Explain in detail (FOR THIS I HAVE WRITTEN
A TWO ANSWERS CHOOSE IN THEM AND WRITE
ANSWER: It is better to have more than one program at a time sharing the memory and other
resources of the machine. If we knew in advance itself that exactly which programs were to be
executed concurrently , we could assign addresses when the programs were assembled so that they
would fit together without overlap or wasted space. Most of the time, however it is not practical to
plan program execution this closely. (We usually do not know exactly when jobs will be submitted,
exactly how long they will run, etc.) Because of this, it is desirable to be able to load a program into
memory wherever there is room for it. In such a situation the actual starting address of the program
is not known until load time.
Example
Absolute program, starting address 1000
e.g. 55 101B LDA THREE 00102D
Relocate the program to 2000
e.g. 55 101B LDA THREE 00202D
Each Absolute address should be modified
Example
Except for absolute address, the rest of the instructions need not be modified
not a memory address (immediate addressing)
PC-relative, Base-relative
The program that require modification at load time are those that specify direct addresses
Explain SIC Mach
STA LENGTH
LENGTH = 1033
(PC) =1026
A 1033-1026 =D
0F200D
S Sometimes it is required to load and run several programs at the same time. The system
must be able to load these programs wherever there is place in the memory. Therefore the
exact starting is not known until the load time.
Absolute Program
In this the address is mentioned during assembling itself. This is called Absolute Assembly.
Consider the instruction:
This statement says that the register A is loaded with the value stored at location 102D.
Suppose it is decided to load and execute the program at location 2000 instead of location
Explain SIC Mach
1000. Then at address 102D the required value which needs to be loaded in the register A
is no more available. The address also gets changed relative to the displacement of the
program. Hence we need to make some changes in the address portion of the instruction
so that we can load and execute the program at location 2000. Apart from the instruction
which will undergo a change in their operand address value as the program load address
changes. There exist some parts in the program which will remain same regardless of where
the program is being loaded.
A
Since assembler will not know actual location where the program will get loaded, it cannot
make the necessary changes in the addresses used in the program. However, the assembler
identifies for the loader those parts of the program which need modification. An object
program that has the information necessary to perform this kind of modification is called
the relocatable program.
The above diagram shows the concept of relocation. Initially the program is loaded at location 0000.
The instruction JSUB is loaded at location 0006. The address field of this instruction contains 01036,
which is the address of the instruction labeled RDREC. The second figure shows that if the program is
to be loaded at new location 5000. The address of the instruction JSUB gets modified to new location
6036. Likewise the third figure shows that if the program is relocated at location 7420, the JSUB
instruction would need to be changed to 4B108456 that correspond to the new address of RDREC.
Exam
Explain SIC Mach
The only part of the program that require modification at load time are those that specify
direct addresses. The rest of the instructions need not be modified. The instructions which
doesn’t require modification are the ones that is not a memory address (immediate
addressing) and PC-relative, Base-relative instructions. From the object program, it is not
possible to distinguish the address and constant The assembler must keep some
information to tell the loader. The object program that contains the modification record is
called a relocatable program.
A
For an address label, its address is assigned relative to the start of the program (START 0).
The assembler produces a Modification record to store the starting location and the length
of the address field to be modified. The command for the loader must also be a part of the
object program. The Modification has the following format:
Modification record
Col. 1 M
Col. 2-7 Starting location of the address field to be modified, relative to the
One modification record is created for each address to be modified The length is stored
S in half-bytes (4 bits) The starting location is the location of the byte containing the leftmost
bits of the address field to be modified. If the field contains an odd number of half-bytes,
the starting location begins in the middle of the first byte.
Source Object
Assembler Linker
Program Code
Executable
Code
Loader
Exam
Explain SIC Mach
Fundamental functions
Machine dependency
EXAMPLE:
Exam
Explain SIC Mach
S
Explain SIC Mach
A ANSWER:
❖ Header
Col. 1 H
Col. 2~7 Program name
Col. 8~13 Starting address (hex)
Col. 14-19 Length of object program in bytes (hex)
❖ Text
Col.1 T
Col.2~7 Starting address in this record (hex)
Col. 8~9 Length of object code in this record in bytes (hex)
Col. 10~69 Object code (69-10+1)/6=10 instructions
❖ End
Col.1 E
S Col.2~7 Address of first executable instruction (hex)
(END program_name)
❖ Modification record
Col 1 M
Col 2-7 Starting location of the address field to be
modified, relative to the beginning of the program
Col 8-9 length of the address field to be modified, in half-
bytes
Exam
Explain SIC Mach
Exam
Explain SIC Mach
The algorithm scans the first statement START and saves the operand field (the address) as the starting address
of the program. Initializes the LOCCTR value to this address. This line is written to the intermediate line. If no
operand is mentioned the LOCCTR is initialized to zero. If a label is encountered, the symbol has to be entered
in the symbol table along with its associated address value. If the symbol already exists that indicates an entry
of the same symbol already exists. So an error flag is set indicating a duplication of the symbol. It next checks for
the mnemonic code, it searches for this code in the OPTAB. If found then the length of the instruction is added
to the LOCCTR to make it point to the next instruction. If the opcode is the directive WORD it adds a value 3 to
the LOCCTR. If it is RESW, it needs to add the number of data word to the LOCCTR. If it is BYTE it adds a value
A one to the LOCCTR, if RESB it adds number of bytes. If it is END directive then it is the end of the program it finds
the length of the program by evaluating current LOCCTR – the starting address mentioned in the operand field
of the END directive. Each processed line is written to the intermediate file.
Exam
Explain SIC Mach
Here the first input line is read from the intermediate file. If the opcode is START, then this
line is directly written to the list file. A header record is written in the object program
which gives the starting address and the length of the program (which is calculated during
pass 1). Then the first text record is initialized. Comment lines are ignored. In the
instruction, for the opcode the OPTAB is searched to find the object code. If a symbol is
there in the operand field, the symbol table is searched to get the address value for this
which gets added to the object code of the opcode. If the address not found then zero
value is stored as operands address. An error flag is set indicating it as undefined. If
symbol itself is not found then store 0 as operand address and the object code instruction
is assembled.
A If the opcode is BYTE or WORD, then the constant value is converted to its equivalent object
code( for example, for character EOF, its equivalent hexadecimal value ‘454f46’ is stored).
If the object code cannot fit into the current text record, a new text record is created and
the rest of the instructions object code is listed. The text records are written to the object
program. Once the whole program is assemble and when the END directive is
encountered, the End record is written.
10.) Generate the complete object program for the SIC source program given
below:-
SUM START 4000
LDA ZERO
TIX COUNT
JLT LOOP
STA TOTAL
RSUB
COUNT RESW 1
ZERO WORD 0
TOTAL RESW 1
END FIRST
Exam
Explain SIC Mach
MODULE 2
ASSEMBLER – 2
1.) What are control sections? Explain how linking is performed between
control sections.
ANSWER: A control section is a part of the program that maintains its identity after
assembly; each control section can be loaded and relocated independently of the
others. Different control sections are most often used for subroutines or other logical
subdivisions. The programmer can assemble, load, and manipulate each of these
control sections separately
Because of this, there should be some means for linking control sections together. For
example, instructions in one control section may refer to the data or instructions of other
control sections. Since control sections are independently loaded and relocated, the
assembler is unable to process these references in the usual way. Such references between
different control sections are called external references.
The assembler generates the information about each of the external references that will
allow the loader to perform the required linking. When a program is written using multiple
control sections, the beginning of each of the control section is indicated by an assembler
directive
The syntax
secname CSECT
Control sections differ from program blocks in that they are handled separately by the
assembler. Symbols that are defined in one control section may not be used directly
another control section; they must be identified as external reference for the loader to
It is the statement in a control section, names symbols that are defined in this section but
may be used by other control sections. Control section names do not need to be named in
the EXTREF as they are automatically considered as external symbols.
It names symbols that are used in this section but are defined in some other control section.
The order in which these symbols are listed is not significant. The assembler must include
proper information about the external references in the object program that will cause the
loader to insert the proper value where they are required.
2.) Distinguish between literal and immediate operands. How does the
assembler handle the literal operands?
ANSWER:
Example:
Exam
Explain SIC Mach
All the literal operands used in a program are gathered together into one or more literal
pools. This is usually placed at the end of the program. The assembly listing of a program
containing literals usually includes a listing of this literal pool, which shows the assigned
addresses and the generated data values. In some cases it is placed at some other location
in the object program. An assembler directive LTORG is used. Whenever the LTORG is
encountered, it creates a literal pool that contains all the literal operands used since the
beginning of the program. The literal pool definition is done after LTORG is encountered.
It is better to place the literals close to the instructions.
A
A literal table is created for the literals which are used in the program. The literal table
contains the literal name, operand value and length. The literal table is usually created as a
hash table on the literal name.
Implementation of Literals:
During Pass-1:
The literal encountered is searched in the literal table. If the literal already exists, no action is taken;
if it is not present, the literal is added to the LITTAB and for the address value it waits till it encounters
LTORG for literal definition. When Pass 1 encounters a LTORG statement or the end of the program,
the assembler makes a scan of the literal table. At this time each literal currently in the table is
assigned an address. As addresses are assigned, the location counter is updated to reflect the number
of bytes occupied by each literal.
During Pass-2:
The assembler searches the LITTAB for each literal encountered in the instruction and replaces it with
S
its equivalent value as if these values are generated by BYTE or WORD. If a literal represents an address
in the program, the assembler must generate a modification relocation for, if it all it gets affected due
to relocation. The following figure shows the difference between the SYMTAB and LITTAB
Exam
Explain SIC Mach
3.) What is a program block? How does the assembler handle the program
blocks?
ANSWER:
Program blocks allow the generated machine instructions and data to appear in the object
program in a different order by Separating blocks for storing code, data, stack, and larger
data block.
A
Assembler Directive USE:
USE [blockname]
At the beginning, statements are assumed to be part of the unnamed (default) block. If no
USE statements are included, the entire program belongs to this single block. Each
program block may actually contain several separate segments of the source program.
Assemblers rearrange these segments to gather together the pieces of each block and
assign address. Separate the program into blocks in a particular order. Large buffer area is
moved to the end of the object program. Program readability is better if data areas are
placed in the source program close to the statements that reference them.
Exam
Explain SIC Mach
--
--
--
95 1033 RETADRRESW 1
In the above example in line number 10 the instruction STL will store the linkage register with the
contents of RETADR. But during the processing of this instruction the value of this symbol is not known
as it is defined at the line number 95. Since I single-pass assembler the scanning, parsing and object
code conversion happens simultaneously. The instruction is fetched; it is scanned for tokens, parsed
for syntax and semantic validity. If it valid then it has to be converted to its equivalent object code.
For this the object code is generated for the opcode STL and the value for the symbol RETADR need
to be added, which is not available.
Due to this reason usually the design is done in two passes. So a multi-pass assembler resolves the
S
forward references and then converts into the object code. Hence the process of the multi-pass
assembler can be as follows:
Pass-1
Perform some processing of assembler directives such as RESW, RESB to find the length of data areas
for assigning the address values.
Exam
Explain SIC Mach
Pass-2
Perform the processing of the assembler directives not done during pass-1.
A Forward reference:
Symbols that are defined in the later part of the program are called forward referencing.
There will not be any address value for such symbols in the symbol table in pass 1.
EQU Statement:
Most assemblers provide an assembler directive that allows the programmer to define
symbols and specify their values. The directive used for this EQU (Equate). The general form
of the statement is
S
Symbol EQU value
This statement defines the given symbol (i.e., entering in the SYMTAB) and assigning to it
the value specified. The value can be a constant or an expression involving constants and
any other symbol which is already defined. One common usage is to define symbolic names
that can be used to improve readability in place of numeric values. For example
+LDT #4096
Exam
Explain SIC Mach
This loads the register T with immediate value 4096, this does not clearly what exactly this
value indicates. If a statement is included as:
+LDT #MAXLEN
A
II.) LTORG :An assembler directive LTORG is used in literal operands. Whenever the LTORG
is encountered, it creates a literal pool that contains all the literal operands used since the
beginning of the program. The literal pool definition is done after LTORG is encountered.
It is better to place the literals close to the instructions.
During Pass-1:
The literal encountered is searched in the literal table. If the literal already exists, no action
is taken; if it is not present, the literal is added to the LITTAB and for the address value it
waits till it encounters LTORG for literal definition. When Pass 1 encounters a LTORG
statement or the end of the program, the assembler makes a scan of the literal table. At this
time each literal currently in the table is assigned an address. As addresses are assigned,
the location counter is updated to reflect the number of bytes occupied by each literal.
During Pass-2:
S
The assembler searches the LITTAB for each literal encountered in the instruction and
replaces it with its equivalent value as if these values are generated by BYTE or WORD. If a
literal represents an address in the program, the assembler must generate a modification
relocation for, if it all it gets affected due to relocation.
The following figure shows the difference between the SYMTAB and LITTAB
Exam
Explain SIC Mach
SYMBOL TYPE
BUFFER RELATIVE
FIRST RELATIVE
MAXLEN ABSOLUTE
LENGTH ABSOLUTE
BUFFEND RELATIVE
Classify the following into absolute, relative or neither absolute nor relative expressions:
i. BUFFER – FIRST
v. BUFFER – MAXLEN
vi. 2 * LENGTH
vii. 2 *MAXLEN – 1
Exam
Explain SIC Mach
ANSWERS:
vi. 2 * LENGTH =
vii. 2 *MAXLEN – 1 =
A control section is a part of the program that maintains its identity after assembly;
each control section can be loaded and relocated independently of the others.
Different control sections are most often used for subroutines or other logical
S subdivisions. The programmer can assemble, load, and manipulate each of these
control sections separately
Because of this, there should be some means for linking control sections together. For
example, instructions in one control section may refer to the data or instructions of other
control sections. Since control sections are independently loaded and relocated, the
assembler is unable to process these references in the usual way. Such references between
different control sections are called external references.
The assembler generates the information about each of the external references that will
allow the loader to perform the required linking. When a program is written using multiple
control sections, the beginning of each of the control section is indicated by an assembler
directive
Exam
Explain SIC Mach
The syntax
secname CSECT
Control sections differ from program blocks in that they are handled separately by the
assembler. Symbols that are defined in one control section may not be used directly
A
another control section; they must be identified as external reference for the loader to
handle. The external references are indicated by two assembler directives:
It is the statement in a control section, names symbols that are defined in this section but
may be used by other control sections. Control section names do not need to be named in
the EXTREF as they are automatically considered as external symbols.
It names symbols that are used in this section but are defined in some other control section.
The order in which these symbols are listed is not significant. The assembler must include
proper information about the external references in the object program that will cause the
loader to insert the proper value where they are required.
Exam