Upload
ledung
View
218
Download
0
Embed Size (px)
Citation preview
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER – 13 EXAMINATION Subject Code: 12263 Model Answer Page No: 1 / 34 ___________________________________________________________________________________
Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in the model answer scheme. 2) The model answer and the answer written by candidate may vary but the examiner may try to assess the understanding level of the candidate. 3) The language errors such as grammatical, spelling errors should not be given more Importance (Not applicable for subject English and Communication Skills). 4) While assessing figures, examiner may give credit for principal components indicated in the figure. The figures drawn by candidate and model answer may vary. The examiner may give credit for any equivalent figure drawn. 5) Credits may be given step wise for numerical problems. In some cases, the assumed constant values may vary and there may be some difference in the candidate’s answers and model answer. 6) In case of some questions credit may be given by judgement on part of examiner of relevant answer based on candidate’s understanding. 7) For programming language papers, credit may be given to any other program based on equivalent concept.
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER – 13 EXAMINATION Subject Code: 12263 Model Answer Page No: 2 / 34 ___________________________________________________________________________________
Q1a)i) What is System Software? Explain evolution of System Programming.
(2 marks for definition 2 marks Evolution)
These are the programs that help in the effective execution of the application programs and allow the
application programmer to focus on the application to be developed without concerning about the
internal detail of the system
e.g.
Assembler
Macroprocessor
Loader
Linker
Compiler
Editor
Interpreter
Operating System
OR
The software that controls the operations of a computer system. It is a group of programs rather than
one program.
Evolution of System Software
1. The earliest computers were entirely programmed in the machine language.
2. Programmers would write out the symbolic program on sheets of paper, hand-assemble into
machine code and then toggle the machine code into the computer.
3. Assemblers solved the problem by allowing the programmers to write program in terms of
symbolic names and binding the names to machine addresses.
4. The relocating loader allowed the users of the sub-programs to write each sub-program as it
starts at location zero.
5. Linkers and loaders divided up the work, with linker doing part of address binding, assigning
address with each program and the loader doing a final relocation step to assign.
6. Linkers had to deal with object code generated by high level programming languages such as
FORTRAN.
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER – 13 EXAMINATION Subject Code: 12263 Model Answer Page No: 3 / 34 ___________________________________________________________________________________
7. Multiple copies of the same program were frequently run at the same time, compilers and the
assemblers were modified to create object code in multiple sections with one section for read
only code another code for writable data.
Q1a)ii) Bucket sort with example (2 marks for explanation, 2 marks example)
This sort involves examining the least significant digit of keyboard first, and the item is then
assigned to a bucket uniquely dependent on the value of the digit. After all items have been
distributed, the “buckets” items are merged in order and then the process is repeated until no more
digits are left. A number system of base P requires P buckets.
Q1a)iii) General Design of the assembler
(4 marks for six steps)(Marks should be allotted even if steps are mentioned)
Assembler is a language translator that takes as input assembly language program (ALP) and generates its
machine language equivalent along with information required by the loader.
ALP Assembler Machine language equivalent + Information required by the loader
Six general design Procedure
1. Specify the problem
2. Specify the data structure(database)
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER – 13 EXAMINATION Subject Code: 12263 Model Answer Page No: 4 / 34 ___________________________________________________________________________________
3. Define format of data structure.
4. Specify the algorithm
5. Look for modularity
6. Repeat 1 through 5 steps
Assembler requires two passes as to overcome forward reference problem. So we make two passes.
Purpose of pass 1 is to define symbols and literals. Purpose of pass 1 is to generate instruction and
the data i.e. object program.
Different databases are used by pass 1
1. Original source card
2. Location counter(LC)
3. Mnemonic opcode table (MOT)
4. Pseudo opcode table (POT)
5. Symbol table (ST)
6. Literal table (LT)
7. Copy file
Databases used by pass2
1. Copy file
2. Location counter(LC)
3. Machine opcode table (MOT)
4. Pseudo opcode table (POT)
5. Symbol table (ST)
6. Literal table (LT)
7. Base table (BT)
8. INST workspace
9. Punched card workspace
10. Printline workspace
11. Object card
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER – 13 EXAMINATION Subject Code: 12263 Model Answer Page No: 5 / 34 ___________________________________________________________________________________
Q1a)iv) Macro definition table)(2 marks for MDT 2 marks for ALA)
Macro Definition Table (MDT)
Index Definition
MDT is used to save the macro definition along with MEND statement. Each parameter is re[placed
by the index notation. In pass 1 MDT is used to save the macro definition. In pass 2 MDT is used for
performing macro expansion
Argument List Array (ALA)
Index Argument
It is used for simplifying the parameter replacement procedure.
In pass 1 ALA is used to replace the formal parameter by three respective index notations
In pass 1 ALA is used to replace the index notations by three actual parameters.
Q1b)i)Components of System Software(1 mark for listing, 1 mark each for any 5 system software
definition)
Components of System software
1. Assembler is a language translator that takes as input assembly language program (ALP) and
generates its machine language equivalent along with information required by the loader.
ALP Assembler Machine language equivalent + Information required by the loader
2. Macros:
The assembly language programmer often finds that certain set of instructions get repeated
often in the code. Instead of repeating the set of instructions the programmer can take the
advantage of macro facility where macro is defined to be as
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER – 13 EXAMINATION Subject Code: 12263 Model Answer Page No: 6 / 34 ___________________________________________________________________________________
“Single line abbrevation for a group of instructions”
The template for designing a macro is as follows
MACRO Start of definition
----------- Macro Name
----------
----------
----------
----------
----------
----------
----------
MEND End of def.
3. Loader: It is responsible for loading program into the memory, prepare them for execution
and then execute them.
OR
Loader is a system program which is responsible for preparing the object programs for
execution and start the execution.
Functions of loader
a. Allocation
b. Linking
c. Relocation
d. Loading
Allocation: Allocate the space in the memory where the object programs can be loaded for
execution.
Linking: Resolving external symbol reference
Relocation: Adjust the address sensitive instructions to the allocated space.
Loading: Placing the object program in the memory in to the allocated space.
4. Linker: A linker which is also called binder or link editor, is a program that combines object
modules together to form a program that can be executed. Modules are parts of a program.
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER – 13 EXAMINATION Subject Code: 12263 Model Answer Page No: 7 / 34 ___________________________________________________________________________________
5. Compiler: Compiler is a language translator that takes as input the source program(Higher
level program) and generates the target program (Assembly language program or machine
language program)
Source Program Compiler Target program
Error Messages
Since the process of compilation is very complex it is divided in to several phases.
(A phase is a logical unit of work that takes as input one representation and generates another
representation. )
The phases are as follows
1. Lexical Analysis
2. Syntax analysis
3. Sementic Analysis
4. Intermediate code generation
5. Code optimization
6. Code Generation
Q.1] b) ii)(03-marks for diagram, 03-marks for explanation)
Draw and Explain phases of compiler
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER – 13 EXAMINATION Subject Code: 12263 Model Answer Page No: 8 / 34 ___________________________________________________________________________________
Lexical Phase:
1. The main task is to read the source program and produce as output a sequence of tokens that the
parser uses for syntax analysis.
2. This reading of source program is called scanning the source program.
3. Scanners recognize keywords, operators and identifiers as well as integers, floating point
numbers, character strings and other similar items that from part of the source program.
4. The lexical analyzer collects information about tokens into their associated attributes.
Syntax Phase
1. The function of syntax phase is to recognize the major constructs of the language and to call
appropriate action routines that will generate intermediate form or matrix for these constructs.
2. In syntax analysis we require the reductions.
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER – 13 EXAMINATION Subject Code: 12263 Model Answer Page No: 9 / 34 ___________________________________________________________________________________
3. This intermediate code or intermediate representation is actually a hierarchical structure of a PL
statement and is called as a parse tree.
Sementic analysis:
This phase performs the check on the meaning of the statement and performs the necessary
modifications in the parse tree representation (if the structure of compiler does not include sementic
analysis then in such a case sementic analysis is assumed to take place within the syntax analysis
phase)
Intermediate code generation:
This phase takes as input the parse tree representation and generates an intermediate representation
to break the complexity of the statement and hence helps in faster translation.
Code Optimization:
This phase is responsible for generating an optimized intermediate representation so that the
resulting code would get executed faster.
Code generation:
This phase is responsible for generating the target program which can be assembly or machine
language program (if the compiler generates an assembly language program then assembler must run
after compiler to generate the object program, hence in a compiler there is an integrated assembler.)
Q.2] a) (04-marks for card, 04-marks for flowchart)
Design of absolute loader.
Assembler takes as input the original source cards and generates the object cards which contain
the object program in a format required by a loader.
Absolute loader requires two types of cards:
i. TXT cards
ii. Transfer cards
TXT cards
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER – 13 EXAMINATION Subject Code: 12263 Model Answer Page No: 10 / 34 ___________________________________________________________________________________
Card type Count Addr Content
0
i. Card type: It is always 0 for TXT cards.
ii. Count: It indicates in bytes the amount of binary information should be loaded into the
memory
iii. Addr: It indicates the location to which the binary information should be loaded into the
memory.
iv. Contents: It contains the binary information.
Transfer Cards
Card type Count Addr Content
1 0
i. Card type: It is always 1 for transfer card.
ii. Count: It is always 0 for transfer card as this card does not contain any binary
information.
iii. Addr: It indicates the location from which the execution of the program should begin.
iv. Content: It is blank as this card contain no binary information.
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER – 13 EXAMINATION Subject Code: 12263 Model Answer Page No: 11 / 34 ___________________________________________________________________________________
Q.2] b) (04-marks for code generation, 04-marks for code optimization)
Explain code generation and optimization with examples.
1. Code Optimization: there are two types of optimization performed by a compiler, machine
dependent and machine independent.
Machine dependent optimization is so intimately related to the instructions that get generated
that it was incorporated in to the code generation phase.
Whereas machine independent optimization was done in a separate optimization.
2. Compile time compute:
Doing computation involving constant at compile time save both space and execution time for
the object program.
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER – 13 EXAMINATION Subject Code: 12263 Model Answer Page No: 12 / 34 ___________________________________________________________________________________
The algorithm for this optimization technique
1. Scan the matrix
2. Look for operators, both of whose operands were literals.
3. Whenever it found such an operation, it would evaluate it, create new literal, delete the old
lines.
4. Replace all references to it with the uniform symbol for the new literal.
5. Continue scanning the matrix for more possible computations.
3. Boolean expression optimization: We may use the properties of Boolean expression to shorten
their computation.
4. Move invariant computation outside of loops: if computation within a loop depends on a variable
that does not change within that loop, then computation may be moved outsode the loop.
a. Recognition of invariant computation
b. Discovering where to move the invariant computation
c. Moving the invariant computation
Algorithm: The possible algorithm for four optimization techniques are as follows:
1. Elimination of common subexpression
2. Compile time compute.
3. Boolean expression optimization.
4. Move invariant computation outside of loops.
Q.2] c) (04-marks for algorithm, 04-marks for matrix)
Write the algorithm for elimination and common sub expressions. Apply it for the following
statement and show the desired matrix
B=A
A=C*D*(D*C+B)
The elimination algorithm must:
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER – 13 EXAMINATION Subject Code: 12263 Model Answer Page No: 13 / 34 ___________________________________________________________________________________
1. Place the matrix in a form so that common subexpressions can be recognized.
2. Recognize two subexpressions as being equivalent
3. Eliminate one of them
4. Alter the rest of the matrix to reflect the elimination of this entry.
Once it has modified entries within a given statement, this algorithm might also want to check to see
if its modifications have created any additional common subexpressions.
A possible algorithm for the elimination of common subexpressions would:
1. Order the operands of the + and * operators alphabetically – check each entry and change
those that are backwards (only M3 and M4 need to be switched)
2. Realize statement boundaries – in this case merely separate them using the = operators.
3. Look for common subexpressions – compare M2 with M3, M4, M5. M3 is the only match so
delete M3 by changing the pointers of M2 and M4.
4. Alter rest of matrix to reflect deleted entry, e.g. change all references of M3 to M2.
5. Rescan matrix for possible created common subexpressions repeat 1 through 5 until no
changes occur.
6. Eliminate from the temporary storage table any MTX entries that are no longer needed.
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER – 13 EXAMINATION Subject Code: 12263 Model Answer Page No: 14 / 34 ___________________________________________________________________________________
Q.3] a)(04-marks for explanation)
Explain Operating system as “Manager of System”.
OS system provides an orderly and controlled allocation of the processors, memories and I/O
devices. When a computer has multiple users the need for managing and protecting the memory, I/O
devices and other devices is greater. Thus the primary task of OS is to keep track of who is using
which resource, to grant resource requests, to mediate conflicting requests from different programs
etc.
Resource management includes multiplexing resources in two ways - "in time" and "in space".
(i)When a resource is time multiplexed different programs or different users gets their turn to use
that resource. eg: Printer. (ii)When a resource is space multiplexed instead of taking turns, the
resource is shared among them, ie each one gets a part of the resource. eg: Sharing main memory,
hard disk etc.
Following diagram illustrates operating system as system manager.
Human Operators
Application Programming
I/O Prog, file system, Scheduler, Libraries, Memory Mngt., Device Mngt.
Loaders, Text editors, Debugging aids, searching & sorting
Compilers, Assemblers, Macro processors
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER – 13 EXAMINATION Subject Code: 12263 Model Answer Page No: 15 / 34 ___________________________________________________________________________________
Q.3] b) (02-marks for listing, 02-explanation of any two)
Explain the data structures of Assembler Pass I.
Datastructures used by the first pass of assembler:
Location counter (LC) to keep track of location of each instruction.
Machine Operation Table (MOT) that consists symbolic mnemonic for each instruction along
with its length.
Pseudo Operation Table (POT) that indicates symbolic mnemonic and action to be taken for
each pseudo op in pass1
Symbol Table (ST) that is used to store each label and its corresponding value.
Literal Table (LT) that is used to store each literal and its corresponding assigned location.
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER – 13 EXAMINATION Subject Code: 12263 Model Answer Page No: 16 / 34 ___________________________________________________________________________________
Q.3] c) (02-marks each any two)
Explain advanced macro facilities.
Advanced macro facilities are aimed at supporting semantic expansion. These facilities can be
grouped into:
1. Facilities for alteration of flow of control during expansion.
2. Expansion time variables
3. Attributes of parameters.
Alteration of flow of control during expansion
Two features are provided to facilitate alteration flow of control during expansion.:
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER – 13 EXAMINATION Subject Code: 12263 Model Answer Page No: 17 / 34 ___________________________________________________________________________________
1. Expansion time sequencing symbols
2. Expansion time statements AIF, AGO and ANOP.
Expansion time variables:
Expansion time variables (EV‟s) are variables which can only be used during the expansion of
macro calls. A local EV is created for use only during a particular macro call. A global EV exists
across all macro calls situated in a program and can be used in any macro which has a declaration for
it. Local and global EV‟s are created through declaration with the following syntax:
LCL <EV specification>[, < EV specification>…]
GBL <EV specification>[, < EV specification>…]
Attributes of formal parameters:
An attribute is written using the syntax
<attribute name> ‟ <formal parameter spec>
And represents information about the value of the formal parameter, i.e. about the corresponding
actual parameter. The type, length and size attributes have the names T, L and S.
MACRO
DCL_CONST &A
AIF (L‟ &A EQ 1) . NEXT
_ _
.NEXT _ _
_ _
MEND
Here expansion time control is transferred to the statement having .NEXT in its label field only if the
actual parameter corresponding to the formal parameter A has the length of „l‟
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER – 13 EXAMINATION Subject Code: 12263 Model Answer Page No: 18 / 34 ___________________________________________________________________________________
Q.3] d) (01-mark for diagram, 01-mark each for terms)
Draw a schematic diagram of program execution and explain following terms:
Figure: Schematic of program execution.
i) Translator: It outputs the program form called object module for the program.
ii) Linker: The Linker processes a set of object modules to produce a ready to execute program form
which can be called as binary program.
iii) Loader: The loader loads this program into the memory for the purpose of execution. The object
module (s) and ready to execute program forms can be stored in the form of files for repeated use.
Q.3] e) (04-marks for explanation with databases)
Explain the lexical phase of compiler.
Algorithm of Lexical Analysis phase of compiler is as follows
The first tasks of the lexical analysis algorithm are to the input character string into token.
The second is to make the appropriate entries in the tables.
A token is a substring of the input string that represents a basic element of the language. It may
contain only simple characters and may not include another token. To the rest of the compiler, the
token is the smallest unit of currency. Only lexical analysis and the output processor of the assembly
phase concern themselves with such elements as characters. Uniform symbols are the terminal
symbols for syntax analysis.
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER – 13 EXAMINATION Subject Code: 12263 Model Answer Page No: 19 / 34 ___________________________________________________________________________________
Lexical analysis recognizes three types of token: terminal symbols, possible identifiers, and literals.
It checks all tokens by first comparing them with the entries in the terminal table. Once a match is
found, the token is classified as a terminal symbol and lexical analysis creates a uniform symbol of
type „TRM‟, and inserts it in the uniform symbol table. If a token is not a terminal symbol, lexical
analysis proceeds to classify it as a possible identifier or literal. Those tokens that satisfy the lexical
rules for forming identifiers are classified as “possible identifiers”.
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER – 13 EXAMINATION Subject Code: 12263 Model Answer Page No: 20 / 34 ___________________________________________________________________________________
Q.4] a) (02-marks for diagram, 02-marks for explanation)
i) How to improve the assembler design.
Some organizational issues in assembler design, like the placement and access of tables and IC,
with respect to the schematic shown in the fig
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER – 13 EXAMINATION Subject Code: 12263 Model Answer Page No: 21 / 34 ___________________________________________________________________________________
For efficiency reasons SYMTAB must remain in main memory throughout Passes I and II of the
assembler. LITTAB is not accessed as frequently as SYMTAB, however it may be accessed
sufficiently frequently to justify its presence in the memory. If memory is at a premium, it is possible
to hold only part of LITTAB in the memory because only the literals of the current pool need to be
accessible at any time. For obvious reasons, no such partitioning is feasible for SYMTAB. OPTAB
should be in memory during Pass I.
Q.4] a) (01-mark each)
ii) Explain the following terms.
1) Binder: A binder is a program that performs the same functions as the direct-linking loader in
“binding” subroutines together, but rather than placing the relocated and linked text directly into
memory, it outputs the text as a file or card deck. This output file is in a format ready to be loaded
and is typically called a load module.
2) Dynamic Loader: the portion of the loader that actually intercepts the “calls” and loads the
necessary procedure is called the overlay supervisor or simply the flipper. This overall scheme is
called dynamic loading – on call (LOCAL).
3) Linkage Editor: A more sophisticated binder, called a linkage editor, can keep track of the
relocation information so that the resulting load module, as an ensemble, can be further relocated
and thereby loaded anywhere in core.
4) Overlay: An overlay is a part of a program (or software package) which has the same load origin
as some other part(s) of the program. Overlays are used to reduce the main memory requirement of a
program.
Q.4] a) iii) (04-marks for algorithm with databases)
Write an algorithm for Syntax analysis phase.
Syntax analysis phase with databases and example. The function of the syntax phase is to recognize
the major constructs of the language and to call the appropriate action routines that will generate the
intermediate form to matrix for the constructs. Databases involved in syntax analysis are as follows:
Uniform Symbol Table (“UST”): It is created by the lexical analysis phase and containing the source
program in the form of uniform symbols. It is used by the syntax and interpretation phases as the
source of input to the stack. Each symbol from the UST enters the stack only once. Stack: the stack
is the collection of uniform symbols that is currently being worked on by the stack analysis and
interpretation phase. The stack is organized on a Last In First Out (LIFO) basis. The term “Top of
Stack” refers to the most recent entry and “Bottom of Stack” to the oldest entry. Reductions: The
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER – 13 EXAMINATION Subject Code: 12263 Model Answer Page No: 22 / 34 ___________________________________________________________________________________
syntax rules of the source language are contained in the reduction table. The syntax analysis phase is
an interpreter driven by the reductions.
Example:
/ /***/
<idn> PROCEDURE/bgn_proc/S1 ****/4
<any><any><any>/ERROR/S2S1*/2
These three reductions will be the first three of the set defined for the example. The
interpretation is as follows:
1. Start by putting the first three uniform symbols from the UST onto the stack. 2. Test to see if top
three elements are <idn>:PROCEDURE. If they are, call the begin procedure (bgn_proc) action
routine, delete the label and get the next four uniform symbols from the UST onto the stack and go
to reduction 4. If not, call action routine ERROR, remove the third uniform symbol from the stack
get one more from the UST, and go to reduction 2.
The reduction state that all programs must start with a „<label>:PROCEDURE‟ .
The syntax phase deletes the label and the „:‟ , gets four more tokens and interprets reduction
4, which will start parsing of the body of the procedure.
If the first statement is not a <label>: PROCEDURE until a match is found or until all the
symbols in the UST have been tried.
Q.4] a) iv)(02-marks for explanation, 02-marks for example)
Explain conditional macro with example
Two important macro processor pseudo-ops, AIF and AGO, permit conditional reordering of the
sequence of macro expansion. This allows conditional selection of the machine instructions that
appear in expansions of a macro call.
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER – 13 EXAMINATION Subject Code: 12263 Model Answer Page No: 23 / 34 ___________________________________________________________________________________
Consider the following program.
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER – 13 EXAMINATION Subject Code: 12263 Model Answer Page No: 24 / 34 ___________________________________________________________________________________
Labels starting with a period (.) such as .FINI, are macro labels and do not appear in the output of
the macro processor.
AIF is a conditional branch pseudo-op; it performs an arithmetic test and branches only if the tested
condition is true. The AGO is an unconditional branch pseudo-op or „go-to‟ statement.
These statements are directives to the macro processor and do not appear in macro expansions.
AIF and AGO control the sequence in which the macro processor expands the statements in macro
instructions.
Branches and tests in the macro instruction language permit the use of highly general macros that
assemble selectively, and by testing the parameters to each call, omit code not needed.
Q.4] b) i) (03-marks for diagram, 03-marks for explanation)
Explain foundation of system programming.
Figure shows the foundation of system programming
Compilers are systems programs that accept people like languages and translate them into machine
language. Loaders are systems programs that prepare machine language programs for execution.
Macro processors allow programmers to use abbreviations.
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER – 13 EXAMINATION Subject Code: 12263 Model Answer Page No: 25 / 34 ___________________________________________________________________________________
Q.4] b) ii) (02-marks for explanation, 02-marks each for any two databases)
Explain intermediate code generation in compiler.
The purpose of the code generation phase is to produce the appropriate code (assembly or machine
language). It uses the code productions (macro definitions) which define the operators that may
appear in the matrix to produce code. It also references the identifier tables and literal tables in order
to generate proper address and code conversions.
Matrix: Each entry has its operator defined in the code pattern data base. Code generation examines
each entry and looks up the code to be generated in the code patterns.
Identifier table, literal table: are used to determine the data type and locations of the variables
(operands of the matrix) so that proper accessing code with the correct address is generated.
Code productions (macro definition): a permanent data base defining all possible matrix operators.
Q.5) a) (08-marks for correct algorithm with explanation)
Write an algorithm for Assembler First Pass. Explain it in detail.
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER – 13 EXAMINATION Subject Code: 12263 Model Answer Page No: 26 / 34 ___________________________________________________________________________________
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER – 13 EXAMINATION Subject Code: 12263 Model Answer Page No: 27 / 34 ___________________________________________________________________________________
Q.5] b) (02-marks for definition, 06-marks for comparison with example)
What is cross compiler? Write the difference between compiler and interpreter.
A cross compiler is a compiler capable of creating executable code for a platform other than the one
on which the compiler is running. Cross compiler tools are used to generate executables for
embedded system or multiple platforms. It is used to compile for a platform upon which it is not
feasible to do the compiling, like microcontrollers that don't support an operating system. It has
become more common to use this tool for paravirtualization where a system may have one or more
platforms in use.
Use of interpretation avoids the overheads of compilation. This is an advantage during program
development, because a program may be modified very often – in facts it may be modified between
every two executions. However, interpretation is expensive in terms of CPU time, because each
statement is subjected to the interpretation cycle. Hence, conventional wisdom warns against
interpreting a program with large execution. However to make an informed decision in practice, we
need a quantitative basis for a comparison of compilers and interpreters. We introduce the following
notation for this purpose:
tc: average compilation time per statement
te : average execution time per statement.
ti: average interpretation time per statement
note that both compilers and interpreters analyse a source statement to determine its meaning.
During compilation analysis of a statement is followed by code generation while during
interpretation it is followed by actions which implement its meaning. Hence we could assume tc ti.
te, which is the execution time of the compiler generated code for a statement, can be several times
smaller than tc. Let us assume tc = 20.te.
consider a program P. let sizep and stmts_executedp represent the number of statements in P and the
number of statements executed in some execution of P, respectively. We use these parameters to
compute the CPU time required to execute a program using compilation or interpretation. Given
example illustrates how this can be done.
Let sizep = 200. For a specific set of data, let program P execute as follows: 20 statements are
executed for initialization purpose. This is followed by 10 iterations of a loop containing 8
statements, followed by the execution of 20 statements for printing the results. Thus, stmts_executedp
= 20+10 x 8 +20 = 120. Thus
Total execution time using the compilation model
=200.tc + 120.te
206.tc
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER – 13 EXAMINATION Subject Code: 12263 Model Answer Page No: 28 / 34 ___________________________________________________________________________________
Total execution time using the interpretation model
= 120.ti
120.tc
Clearly interpretation is beneficial in this case.
Q.5 c) (04-marks for relocation, 04-marks for linking)
Explain relocation and linking concepts.
Program relocation: It is the process of modifying the addresses used in the address sensitive
instructions of a program such that the program can execute correctly from the designated area of
memory.
Let AA be the set of absolute addresses – instructions or data addresses – used in the instructions of
a program P. AA implies that program P assumes its instructions and data to occupy memory
words with specific addresses. Such a program – called an address sensitive program – contains one
or more of the following:
1. An address sensitive instruction: an instruction which uses an address ai AA.
2. An address constant: a data word which contains an address ai AA.
Linking: It is the process of binding an external reference to the correct link time address.an external
reference is said to be unresolved until linking is performed for it. It is said to be resolved when its
linking is completed.
Consider an application program AP consisting of a set of program units SP={Pi}. A program unit Pi
interacts with another program unit Pj by using addresses of Pj‟s instructions and data in its own
instructions. To realize such interactions Pj and Pi must contain public definitions and external
references as defined in the following:
Public definition: a symbol pub_symb defined in a program unit which may be referenced in other
program units.
External reference: a reference to a symbol ext_symb which is not defined in the program unit
containing the reference.
Q.6] a) (02-marks for address calculation, 02-marks for comparison of sort)
Explain address calculation of sort and comparisons of sort.
This can be one of the fastest types of sorts if enough storage space is available. The sorting is done
by transforming the key into an address in the table that “represents” the key. For example if the key
were four characters long, one method of calculating the appropriate table address would be to
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER – 13 EXAMINATION Subject Code: 12263 Model Answer Page No: 29 / 34 ___________________________________________________________________________________
divide the key by the table length in items, multiply by the length is a power of 2, then the division
reduces to a shift. This sort would take only N* (time to calculate address) if it were known that no
two keys would be assigned the same address. However, in general. This is not the case and several
keys will be reduced to the same address.
Comparison of sorts
Interchange, Radix, Radix-exchange, Shell and address calculation. The characteristics for each of
these sorts are presented below:
Type Average Time (approx) Extra Storage (wasted space)
Interchange A*N2 None
Shell B*N*(log 2(N))2 None
Radix C*N*N log (k) N*P
Radix exchange D*N*log2 (N) K+1
Address calculation E*N 2.2*N (approximate)
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER – 13 EXAMINATION Subject Code: 12263 Model Answer Page No: 30 / 34 ___________________________________________________________________________________
Where N is the table size, K is the maximum key size (32 generally), and P is the radix of the radix
sort. A, B, C, D and E are the constants of proportionality.
Q.6] b) (04-marks for explanation)
Explain the term Hash or Random Entry Searching.
All Binary Search algorithms, which are fast, but can only operate on tables that are ordered
and packed, i.e. tables that will have adjacent items ordered by keywords. Such search
procedures may therefore have to be used in conjunction with a sort algorithm which both
orders and packs the data.
Actually, it is unnecessary for the table to be ordered and packed to achieve good speed in
searching. This is also possible to do considerably better with an unpacked, unordered table,
provided it is sparse, i.e. the number of storage spaces allocated to it exceeds the number of
items to be stored.
It is observed that the address calculation sort gives good results with a sparse table.
However, having to put elements in order slows down the process. A considerable
improvement can be achieved by inserting element in a random (or pseudo-random) way.
The random entry number K is generated from the key by methods similar to those used in
address calculation. If the K th
position is void, then the new element is put there, if not then
some other cell must be found for the insertion.
The first problem is the generation of a random number from the key. It is to design a
procedure that will generate pseudo-random, consistent table positions for keywords. One
fairly good prospect for four character EBCDIC keywords is to simply divide the keyword by
the table length N and use the remainder. This scheme works well as long as N and the key
size (32 bits in case) have no common factors. For a given group of M keywords the
remainders should be fairly evenly distributed over )….(N-1).
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER – 13 EXAMINATION Subject Code: 12263 Model Answer Page No: 31 / 34 ___________________________________________________________________________________
Q.6] c) (04-marks for explanation with example)
Explain implementation of macro calls within macros.
Macro calls are “abbreviations” of instruction sequences, it seems reasonable that such
“abbreviations” should be available within other macro definitions. For example,
MACRO
ADD1 &ARG
L 1, &ARG
A 1, =F‟1‟
ST 1, &ARG
MEND
MACRO
ADDS &ARG1, &ARG2, &ARG3
ADD1 &ARG1
ADD1 &ARG2
ADD1 &ARG3
MEND
Within the definition of the macro „ADDS‟ are three separate calls to a previously defined
macro „ADD1‟. The use of the macro „ADD1‟ has shortened the length of the definition of „ADDS‟
and thus had made it more easily understood. Such use of macros result in macro expansions on
multiple „levels‟ .
Macro calls within macros can involve several levels. For example, the macro ADDS might be
called within the definition of another macro. In fact, conditional macro facilities (such as AIF and
AGO) make it possible for a macro to call itself. So long as this does not cause an infinite loop-so
long as at some point the macro, having been called for the nth
time, decides not to call itself again –
it makes perfectly good sense.
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER – 13 EXAMINATION Subject Code: 12263 Model Answer Page No: 32 / 34 ___________________________________________________________________________________
Q.6] d) (02-marks for diagram, 02-marks for explanation)
Explain the term “Compile and go” loaders with examples.
As a usual practice one method of performing the loader functions is to have to assemble run in one
part of memory and place the assembled machine instructions and data they are assembled, directly
into their assigned memory locations.
When the assembly is completed the assembler causes transfer to the instruction of the program.
This is a simple solution, involving no extra procedures. It is used by the WATFOR FORTRAN
compiler and several other language processors.
Such a loading scheme is commonly called “compile-and-go” or “assembler – and –go”. It is
relatively easy to implement. The assembler simply places the code into core, and the “loader”
consists of one instruction that transfers to the starting instruction of the newly assembled program.
Disadvantages:
1. A portion of memory is wasted because the core occupied by the assembler is unavailable to
the object program.
2. It is necessary to retranslate (assemble) he user‟s program code every time it is run.
3. It is very different to handle multiple subroutines in assembly language and another
subroutine in any programming language.
This last disadvantage makes it very difficult to produce orderly modular programs in the design of
assemblers.
For example assembler is one of the type of compile and go loader which can be depicted in the
following figure:
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER – 13 EXAMINATION Subject Code: 12263 Model Answer Page No: 33 / 34 ___________________________________________________________________________________
Q.6] e) (02-marks each for tools)
Explain compiler writing tools.
There are two types of compiler writing tools:
1. LEX
2. YACC
Which are nothing but language processor development tools as per the following figure:
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
SUMMER – 13 EXAMINATION Subject Code: 12263 Model Answer Page No: 34 / 34 ___________________________________________________________________________________
LEX accepts an input specification which consists of two components. The first component is a
specification of strings representing the lexical unite in L, e.g. id‟s and constants. The second
component is a specification of semantic actions aimed at building an IR. The IR consists of a set of
tables of lexical units and a sequence of tokens for the lexical units occurring in a source statement.
Accordingly, the semantic actions make new entries in the tables and build tokens for the lexical
units.
YACC: Each string specification in the input to YACC resembles a grammar production. The parser
generated by YACC performs reductions according to this grammar. The actions associated with a
string specification are executed when a reduction is made according to the specification. An
attribute is associated with every non terminal symbol. The value of this attribute can be manipulated
during parsing. The attribute can be given any user designed structure.