Sunteți pe pagina 1din 62

SYSTEM SOFTWARE

SYSTEM SOFTWARE

BY : Nishit Kachiya 10MCA20 Institute of Technology

NISHIT KACHIYA

Page 1

SYSTEM SOFTWARE

CHAPTER :-1
(1) Explain The Following Terms .
(a)Application Domain (b)Execution Gap (c)Source program (d)Dynamic Binding (e)Forward Reference (f)Language Translator (k)Execution Domain (g)Specification Gap (l)Language processor (h)Target program (m)Static Binding (i)Binding (n)Preprocessor (j)Language Processor Pass

Application Domain :- An application Domain is a mechanism used to isolate executed software applications from one another so that they do not reflect each other . Execution Domain :-

Execution Gap:- Execution Gap is the gap between the semantics of the programs written in different programming languages . The Execution Gap is bridge by the designer of the programming language processor . Specification Gap :- Specification gap is the semantic gap between two specification of the same task . The specification gap is bridged by the software development team . The semantic gap between the application domain and the execution domain is bridge by the software engineering steps . Language processor :- A language processor is a software which bridges a specification or execution gap .we use the term language processing to describe the activity performed by a language processor.

Fig shows that two language processors. The language processor of part (a) converts a C++ program into a C program , hence it is a preprocessor .the language
NISHIT KACHIYA Page 2

SYSTEM SOFTWARE
translator for C++ since it produces a machine language program in both cases the program are the C program and the machine language program respectively. Source program :- A program form input to a language processor as source program is called a source program . Target program :- A program from input to a language processor as source program as to its output as the target program . The language in which program are written are called source language and target language . Language Translator :- A language translator bridges an execution gap to the machine language of a computer system . An assembler is a language translator whose source language is assembly language . A compiler is any language translator which is not an assembler . Static Binding :- A static binding is a binding performed before the execution of a program begins. Static binding leads to more efficient execution of a program than dynamic binding. Dynamic Binding :- A dynamic binding is a binding performed after the execution of a program has begun. Binding :- A binding is the association of an attribute of a program entity with a value . Preprocessor :- A preprocessor is a language processor which bridges an execution gap but not a language translator . Forward Reference :- A forward reference of a program entity is a reference to the entity which precedes its definition in the program . Language Processor Pass :- A language processor pass is the processing of every statement in a source program, to perform a language processing function.

2) Differentiate between problem oriented and procedure oriented language ?


The language which is only be used for Specific Applications known as problem oriented language. They have large execution gap and this gap is bridged by the translator or interpreter. A program execution activity organized the execution of a program return in a programming language on a computer system. Its source language could be a procedure oriented language or a problem oriented language.

NISHIT KACHIYA

Page 3

SYSTEM SOFTWARE

A procedure oriented language provides general purpose facilities required in most application domain . such a language is independent of specific application domains.

3) Explain Language Processing Activity (Program Generation & Program Execution Activity) in detail.
The fundamental language processing activities can be divided into those that bridge the specification gap and those that bridge execution gap . these activities are : (a) Program Generation Activities (b) Program Execution Activities Program Generation :- A program generator is a software system which accepts the specification of a program to be generated , and generates a program in the target PL. the program generation activity aims at automatic generation of a program. The program generator introduces a new domain between the application and PL domain (program generator domain). Errors Program program specification Program in target Pl Generator

The Specification gap is now the gap between the application domain and the program generator domain. The gap is smaller than the gap between the application domain and the target PL domain . Reduction in the specification gap increases the reliability of the generated program. It is easy for the programmer to write the specification of the program to be generated .

NISHIT KACHIYA

Page 4

SYSTEM SOFTWARE
it is more economical to develop a program generator than to develop a problem oriented language . this is because a problem oriented language suffers a large execution gap between the PL domain and the execution domain whereas the program generator has a smaller semantic gap to the target PL domain. Program Execution :- Two popular models for program execution are Translation and Interpretation . Program Translation : The program translation model bridges the execution gap by translating a program written in a PL, called the source program into an equivalent program in machine language of the computer system , called the target program.

(Figure) :Characteristics of program translation model are : The program must be translated before it can be executed . The translated program may be saved in a file. The saved program may be executed repeatedly. Program Interpretation:- The interpreter reads the source program and stores it in its memory . During interpretation it takes a source statement, determines its meaning and performs actions which implement it . the CPU uses a program counter (PC) to note the address the next instruction to be executed .

(figure)
NISHIT KACHIYA Page 5

SYSTEM SOFTWARE
Characteristics : The source program is retained in the source from itself. A statement is analyzed during its interpretation.

4) What is Intermediate Representation ?


An Intermediate Representation (IR) is a representation of a source program which reflects the effect of some analysis and synthesis task performed during language processing . The first pass performs analysis of the source program and reflects its results in the intermediate representation . The second pass read and analysis the IR, instead of source program, to perform synthesis of target program. The first pass is concerned with source language issues, Hence it is called front end of the language processor .The second pass is concerned with program synthesis for a specific target language, hence it is called the back end of the language processor .

Properties of IR : Ease of Rules :- IR should be easy to construct and analyse. Memory Efficiency :- IR must be compact.

5) What is Programming language grammar ? Explain it in detail .


Grammars are classified on the basis of the nature of production used in them . Each grammar class has its own characteristics and limitations. A grammar G consist of the following components . A finite set N of non terminal symbols . A finite set of terminal symbols . A finite set P of production rules . There are four types of grammars .
NISHIT KACHIYA Page 6

SYSTEM SOFTWARE
Type-0 grammar :- These grammars are also known as phrase structure grammar , it contain production of the form :: = Where both and can be string of Ts and NTs. They are not relevant to specification of programming languages . Type-1 grammar :- These grammars are known as context sensitive grammars because their production specify that derivation or reduction of strings can take place only in specific contexts. A type- 1 production has the form A :: = Thus a string in a sentential form can be replaced by A only when it is enclosed by the strings and . The string and may be empty but must be non empty . these grammars are also not relevant for PL specification . Type-2 grammar :- These grammars impose no context requirement on derivation or reductions. A type-2 production has the form

A :: = These grammar are known as context free grammars . these grammar are ideally suited for programming language specification .ALGOL-60 specification and Pascal Specification are used in type-2 grammar . Type-3 grammar :- Type-3 grammars are characterized by productions of the form A :: = t B | t or A :: = B t | t Those production also satisfy the requirements of type-2 grammars. These grammar is also known as Regular grammar OR Linear grammar . These are further categorized into left-linear and right-linear grammars .

NISHIT KACHIYA

Page 7

SYSTEM SOFTWARE
6) Discuss Front End and Back End of the Toy Compiler.
FRONT END :- The front end performs lexical , syntax and semantic analysis of the source program. Each kind of analysis involves the following functions : 1) Determine validity of a source statement from the view point of the analysis. 2) Determine the content of the source statement. 3) Construct a Suitable representation of the source statement . In Lexical analysis, the content of the lexical class to which each lexical unit belongs, while in syntax analysis it is the syntactic structure of a source statement . In Semantic analysis, it is the meaning of the statement for a declaration statement . it is the set of attributes of a declared variable . For example , syntax analysis uses information concerning the lexical class of lexical units and construct a representation for the syntactic structure of the source statement . Output of the front end : (1) Tables of information (2) An intermediate code (IC)

TABLE : Tables contains the information obtained during different analysis of SP. IC : The IC is a sequence of IC units , each IC unit representing the meaning of one action in SP. Lexical Analysis (Scanning):- Lexical analysis identifies the lexical units in a source statement. Then it classifies the units into different lexical classes , examples:- ids , constants etc. and enters them into different tables . the classification may be based on the nature of the string . Lexical analysis builds a descriptor, called a token , for each lexical unit. A token contain two fields. Class code and Number in class . class code identifies the class to which a lexical unit belongs . number in class is the entry number of the lexical unit in the relevant table. Syntax Analysis (Parsing):- Syntax analysis processes the string of tokens built by lexical analysis to determine the statement class . for example :- assignment statement , if statement etc. then it builds an IC which represent the structure of the statement .
NISHIT KACHIYA Page 8

SYSTEM SOFTWARE
BACK END :- The back end performs memory allocation and code generation.

Memory Allocation :- Memory allocation is a simple task given the presence of symbol table. The memory requirement of an identifier id computed from its type & length .The address of the memory area is entered in the symbol table. Code Generation :- Code generation uses knowledge of the target architecture .The important issues in code generation are : 1) Determine the places where the intermediate results should be kept. 2) Determine which instruction should be used for type conversion operation. 3) Determine which addressing mode should be used for accessing variables.

7) What is ambiguity in Grammatic specification and how we can remove it?


Ambiguity implies the possibility of different interpretations of a source string. For example , A word can have multiple meanings or can be both noun or verb and a sentence can have multiple syntactic structures. Formal language grammars avoid ambiguity at the level of a lexical unit . This is achieved by simple rule that identical strings cant appear on the RHS of more than one production in the grammar . it means that the string can have more than one meaning associated with it. Consider the expression grammar : <exp> :: = <id> | <exp> + <exp> | <exp> * <exp>

NISHIT KACHIYA

Page 9

SYSTEM SOFTWARE
<id> :: = a | b | c

Two parse trees exist for the source string a+b*c according to this grammar. One in which a+b is first reduced to <exp> and another in which b*c is first reduced to <exp>. Eliminating Ambiguity :- An ambiguous grammar should be written to eliminate ambiguity. To reduce the ambiguity in above expression , A grammar must be written such that reduction of * precedes the reduction of + in a+b*c. the normal method to reducing this is to use a hierarchy of NTs in the grammar ..

8) Define language processor (LR)? Explain various language processors , also give application of each.
A language processor is a software which bridges a specification or execution gap .we use the term language processing to describe the activity performed by a language processor.

A language processor abandon generation of the target program if it detects errors in the source program. There are different types of language language processor . Language Translator :- A language translator bridges an execution gap to the machine language of a computer system. Assembler :- An assembler is a language translator whose source language is assembly language. Compiler :- A compiler is any language translator which is not an assembler . Detranslator :- A detranslator bridges the same execution gap as the language translator , but in the reverse direction . Preprocessor :- A Preprocessor is a language processor which bridges an execution gap but is not a language translator. Language migratory :- A language migratory bridges the specification gap between two PLs.

NISHIT KACHIYA

Page 10

SYSTEM SOFTWARE
9) Develop a regular expression for
(i) Integer (ii) Real number (iii) Real number with optional fraction (iv) Identifier Ans : A regular expression for (i) integer is [+ | -] (d)+ (ii) real number is [+ | -] (d)+. (d)+ (iii) real number with optional fraction is [+ | -] (d)+. (d)* (iv) identifier is l(l | d)*

NISHIT KACHIYA

Page 11

SYSTEM SOFTWARE

CHAPTER :-3
1) Define following Terms .
(A)Backtracking (B)Recursive Descend Parser (RD) (C)Predictive Parser (D)Source String Maker (SSM) (E)Prediction (F)Operator Precedence Grammar (G) Simple Precedence Grammar Backtracking :- This mechanism matches every terminal symbol generated during the derivation with the source symbol pointed to the Source String Marker (SSM) Backtracking is performed, if the match fails. This involves resetting CSF and SSM to earlier values. Example Lexically analysed version of the source string a+b*c. Is <id> + <id> * <id> is to be parsed according to the following grammar E ::= T + E | T T ::= V * T | V V ::= <id> Here the prediction making mechanism selects the RHS alternative of a production in a left to right manner. Prediction : this mechanism selects the RHS alternative of a production during prediction making. It must ensure that any String LG can be derived from S. Recursive Descend Parser :- A Recursive Descent parser (RD) is a Variant of top down parsing without backtracking. It uses a set of recursive procedures to perform parsing . It can be implemented in any language supporting recursive procedures. Operator Precedence Grammar:- An operator precedence grammar (OPG) is an operator grammar in which the precedence between operator are unique. Such grammar arise in expressions.

NISHIT KACHIYA

Page 12

SYSTEM SOFTWARE
Simple Precedence Grammar:- Grammar G is a simple precedence grammar if for all terminal and non terminal symbols a, b of G , a unique precedence relation exists for a,b. Source String Maker (SSM):- SSM points to the first unmatched symbol in the source string .

2) What is Parsing ? Explain different parsing techniques .


The goals of parsing is to check the validity of a source string, and to determine its syntactic structure . Parsing is also known as syntactic analysis and parser is used for analyzing a text. The task of the parser is essentially to determine how the input can be derived from the start symbol of the grammar. There are mainly two parsing techniques. 1) Top down parsing 2) Bottom-up parsing Top down parsing :- Top Down Parsing can be viewed as an attempt to find left-most derivation of an input stream by searching for parse tree . Tokens are consumes from left to right . Inclusive choice is used to accommodate ambiguity by expanding all alternative right- hand side of the grammar rules. For a valid source string , a top down parse thus determine a derivation sequence S == > == > == > . Parse tree CSF Parse tree CSF

Top down parsing is also known left-to-left parsing. Bottom-up Parsing :- A bottom up parser constructs a parse tree for a source string through a sequence of reductions . The source string is valid if it can be reduced to S .
NISHIT KACHIYA Page 13

SYSTEM SOFTWARE
Bottom up parsing proceeded in a left-to-right manner .A parser can start with the input and attempt to rewrite it to the start symbol. LR parsers are examples of bottom-up parsers. Another term used for this type of parser Shift-Reduce parsing . In Bottom-up parsing we start with the sentence and try to apply the production rules in reverse, in order to finish up with the start symbol of the grammar. Suppose we have a grammar S -> aABe A ->Abc | b B ->d And the input string is Abbcde Then an instance of bottom-up parsing can be given as aAde -> aABe -> S The basic idea of a bottom-up parser is that we use grammar productions in the opposite way (from right to left). Like for predictive parsing with tables, here too we use a stack to push symbols. If the first few symbols at the top of the stack match the RHS of some rule, then we pop out these symbols from the stack and we push the lhs (left-handside) of the rule. This is called a reduction. For example, if the stack is x * E + E (where x is the bottom of stack) and there is a rule E ::= E + E, then we pop out E + E from the stack and we push E;, the stack becomes x * E. The sequence E + E in the stack is called a handle. But suppose that there is another rule S ::= E, then E is also a handle in the stack.

3) Recursive descent parser is of which type of parser ? Explain how it works by giving suitable example.
A Recursive Descent parser (RD) is a Variant of top down parsing without backtracking. It uses a set of recursive procedures to perform parsing . The advantages of recursive descent parsing are its Simplicity and Generality. It can be implemented in any language supporting recursive procedures. To implement recursive descent parsing, a left-factored grammar is modified to make repeated occurrences of strings more explicit .
NISHIT KACHIYA Page 14

SYSTEM SOFTWARE
These type of parser was very popular for real compiler in the past , but not popular now. Consider the grammar used before for simple arithmetic expressions P ---> E E ---> E + T | E - T | T T ---> T * S | T / S | S S ---> F ^ S | F F ---> ( E ) | char The above grammar won't work for recursive descent because of the left recursion in the second and third rules.

4) What is parsing ? Give Difference between top down parsing and bottom up parsing.
The goal of parsing is to determine the syntactic validity of a source string. If the string is valid, a tree is built for use by subsequent phase of compiler. Top down parsing: Top down parsing attempts to derive a string identical to it by successive application of grammar rules to the grammars distinguished symbol. When such a string is obtained , a tree representing its derivation would be the syntax tree for an input string. Thus if is input-string, a top down parse determines a derivation sequence. S == > .. == > == > Bottom up parsing: A bottom up parse attempts to develop syntax tree for an input string Through a sequence of reduction. If the input string can be reduced to the distinguished symbol, the string is valid. If not, error would be detected and indicated during the process of reduction itself.

5) What is parsing ? What is the goal of parsing .


Source programmed statements are regarded as tokens, building block of language the task of scanning the source statement, recognizing and classifying the various tokens is known as lexical analysis. The part of the compiler that performs this task is commonly called a scanner. After the token scan, each statement in the program must be recognized as some language constructs, such as declaration or an assignment statement described by the grammar. This process is called Syntactic analysis or parsing is performed by the part of compiler called parser.

NISHIT KACHIYA

Page 15

SYSTEM SOFTWARE
Goals: 1. To check the validity of source string 2. To determine the syntactic structure of a source string. For invalid string it reports error, for a valid string it builds a parse tree to reflect the sequences of derivations or reductions performed during parsing.

6) State the Difference between Parse tree and Abstract syntax tree.
Parse tree contain every token of the input as a leaf , and the interior nodes are non terminals in the grammar used to parse. Parse tree represents the source code more closely. A parse tree is a record of the rules (and tokens) used to match some input text. For a language like C the Parse Tree would need to contain nodes for the 'if' keyword, parenthesis, curly braces also.

An abstract syntax tree (AST) represents the structure of a source string in a more economical manner . the word abstract implies that it is a representation designed by a compiler designed for his own purposes. Designer has total control over the information represented in an AST. AST for a source string is not unique, where as a parse tree is unique . AST describes the source code conceptually, it doesn't need to contain all the syntactical elements.

Parse tree

AST

7) State the difference between Scanning and Parsing .


Scanning is the process of recognizing the lexical components in a source string. While parsing is the process of checking the validity of a source string . The reason for separating scanning from parsing is that the lexical features of a language can be specified using Type3 grammars. Scanning identifies the lexical units in a source statement. Then it classifies the units into different lexical classes , examples:- ids , constants etc. and enters them into different tables. the classification may be based on the nature of the string .

NISHIT KACHIYA

Page 16

SYSTEM SOFTWARE
Parsing processes the string of tokens built by lexical analysis to determine the statement class . for example :- assignment statement , if statement etc. then it builds an IC which represent the structure of the statement . The goal of parsing is to check the validity of a source string and to determine its syntactic structure.

8) Advantages of LL(1) parsing technique .


The main advantage of LL(1) parsing is its amenability to automatic construction by a parser generator . The LL(1) parser is much simpler than to implement than LR parser .

9)What do you mean by handle and simple phrase in a bottom up parsing? explain.
Handle :- A handle of a sentential form is the left-most simple phrase in it . For example , E+T is not a simple phrase of the sentential form of E+T*F according to grammar . since its reduction to E does not lead to the distinguished symbol . however T*F is a simple phrase of the sentential form . Simple Phrase :- is a simple phrase of the sentential form.if there exists a production of the grammar A :: = and A is a reduction in the sequence of reductions S .

NISHIT KACHIYA

Page 17

SYSTEM SOFTWARE

CHAPTER :-4
1) List out all assembly language elements ? Discuss assembly languages statements.
Assembler is a program, which translates Assembly language program into machine language program . An assembly language is a machine dependent , low level programming language which is specific to a certain computer system . Compared to the machine language of a computer system , it provides three basic features which simplify programming : Mnemonic Operation Codes :- Use of mnemonic opcodes for machine instructions eliminates the need to memorize numeric operation codes . Symbolic operands :- symbolic names can be associated with data or instructions. These symbolic names can be used as operands in assembly statements. The assembler performs memory buildings to these name ; the programmers doesnt know any details of the memory buildings performed by the assembler. Data declaration :- Data can be declared in a variety of notations, including the decimal notation. It avoids the manual conversion of constants into their internal machine representation. For example , conversion of -5 into (11111010)2 . Assembly Language Statements :An assembly program contains three kinds of statements : 1) Imperative Statements 2) Declaration Statements 3) Assembler Directives

Imperative Statements :- An imperative statement indicates an action to be performed during the execution of the assembled program . each imperative statements typically translates into one machine instruction . Declaration Statements :- the syntax of declaration statements is as follows : [label] DS <constant> [label] DS < value >
NISHIT KACHIYA Page 18

SYSTEM SOFTWARE
The DS (declare storage ) statement reserves area of memory .

A G

DS DS

1 200

The first statement reserves a memory area of 1 word and associates the name A with it .The second statement reserve a block of 200 memory words. The name G is associated with the first word of the block . The DC(declare constant) statement constructs memory words containing constants . ONE DC 1

Associates the name ONE with a memory word containing the value 1 .

Assembler Directives:- Assembler directives tells the assembler to perform certain actions during the assembly of the program . some assembler directives are described here : START <constant > This directive indicates that the first word of the target program generated by the assembler should be placed in the memory word with address <constant >. END [<operand spec>]

This directive indicates the end of the source program . The optional <operand spec> indicates the address of the instruction where the execution of the program should begin. :) The advantages of the assembly language program would be Reduced errors Faster translation Time Changes could be made easier and fast.

NISHIT KACHIYA

Page 19

SYSTEM SOFTWARE
2) Discuss pass structure of assembler .
The pass structure of the assembler is described below. Two Pass Translation :- Two pass translation of an assembly language program can handle forward references easily. LC processing is performed in the first pass and symbols defined in the program are entered into the symbol table . The first pass performs analysis of the source program while the second pass performs synthesis of the target program. The first pass construct an intermediate representation (IR) of the source program used by the second pass. This representation consist of two main components- data Structures, e.g. the symbol table, and a processed form of the source program. The latter components is called intermediate code (IC). Single pass translation :- LC processing and Construction of the symbol table proceed in two pass translation. The problem of forward references is tackled using a process called backpatching. The instruction corresponding to the statement MOVER BREG, ONE

Can be only synthesized since ONE is a forward reference. The need for inserting the second operands address at a later stage can be indicated by adding an entry to the Table of Incomplete Instructions (TII). This entry is a pair (<instruction address>,<symbol>), e.g. (101,ONE) in this case . By the time END statement is processed, the symbol table would contain the addresses of all symbols defined in the source program and TII would contain information describing all forward references . The assembler can now process each entry in TII to complete the instruction. The entries in TII can be processed in an incremental manner.
NISHIT KACHIYA Page 20

SYSTEM SOFTWARE

3) Explain about the data structures used in first pass of the assembler.
Three major data structures used during the first pass of the assembler are: -LITTAB(Literal table) - OPTAB (operation code table) - SYMTAB (Symbol table) LITTAB :- A Table of literals used in the program . The need of LITTAB needs some explanation. A LITTAB entry contains the fields Literal and Address. Literal =5 =1 =1 Address

OPTAB: Operation table contains mnemonic operation code, class and mnemonic information . Mnemonic Opcode MOVER DS START . Class IS DL AD : Mnemonic info (04,1) R#7 R#11

OPTAB can be implemented using hashing function for fast access. The content will never change in Operation table . Implementation can be possible through hash table or array . SYMTAB: Symbol table maintain symbolic label, operand and their corresponding machine. Symbol LOOP NEXT LAST A BACK B Address 202 214 216 217 202 218 lengh 1 1 1 1 1 1

NISHIT KACHIYA

Page 21

SYSTEM SOFTWARE
SYMTAB is dynamic. Processing of an assembly statement begins with the processing of its label field. If it contains a symbol and the value in LC is copied into a new entry of SYMTAB. SYMTAB can be implemented using hashing function for fast access.

4) Explain about the data structures used in the design of a two pass assembler in detail.
The data structures used in two-pass assemblers are given below : 1. Mnemonic Table (MT) 2. Symbol Table (ST) 3. Location Counter (LC) 4. Literal Table (LT) Mnemonic Table (MT) :- It is a data structure used for maintaining the details about the instructions of instruction set of any machine. Itll have mnemonics of the instruction, corresponding hexadecimal opcode and the length of the instruction. The structure of mnemonic table is given below : Mnemonics SUB B ADD B .. HLT Opcode 97 80 . 76 length 1 1 1

The mnemonics table also maintain the format of the instruction . it is also known as machine opcode table. Symbol Table (ST) :- Symbol table maintain the details of the symbols present in assembly language program. The symbols may be labels like identifier names, Attributes. The structure of the symbol table is below : Symbol LOOP NEXT LAST A BACK B Address 202 214 216 217 202 218 lengh 1 1 1 1 1 1

NISHIT KACHIYA

Page 22

SYSTEM SOFTWARE
SYMTAB is dynamic. Processing of an assembly statement begins with the processing of its label field. If it contains a symbol and the value in LC is copied into a new entry of SYMTAB. The data structure for mnemonic table and symbol table can be Hash Table , because of the efficiency in insertion and retrieval. Literal Table (LT):- Constants for which the assembler automatically reserves memory are called literals. A literal is an operand that states the required value directly on an instruction. The literals improve the readability of a program by making the value of the constant apparent in the source statement . Pass I of the assembler builds the Literal Table. It will maintain the details about the literals used in the source program like names and values. Whenever a literal is encountered, new entry will be made in the literal table . At the end of the first pass this literal table sorted in order to remove duplicates .the structure of literal table is below :

Literal name C D =1

Address 8088 8090 8100

Location Counter(LC) :- Location counter is another data structure used to keep track the address of the next memory word. It is a variable, which keeps track of the execution-time address of the instruction . LC needs to know the length of different instructions, hence Mnemonic table can be included to have the length of the instruction. The process of maintaining the address of the next memory word is called as LC processing . the location counter is also called as instruction counter.

5) Explain the significance of various advanced assembler directives with appropriate example . and also explain how they are processed by the assembler .
Assembler directive are the instruction to the assembler .these instruction are neither translated into machine code nor assigned any memory location in the object file . few assembler directives are explained below . ORG(Origine):- The ORIGIN statement is useful when the target program does not consist of consecutive memory words. The syntax of this directive is
NISHIT KACHIYA Page 23

SYSTEM SOFTWARE
ORIGIN <address space > Where < address spec > is < constant >. The assembler maintains a program counter type registered called address counter .this counter maintain the address of the next instruction . ORG 7000 H MVI A, 02 EQU (equate) :- The EQU statement defines the symbol to represent < address space > . it allows user to assign numeric value to a symbol name . the user can use the symbolic value in the program instead of its numeric value. < symbol > EQU < address spec >

Where < address spec > is < constant >. START EQU 0200H This assign the value 0200H to the label start. DB (define byte):- this instruction is used to initialized an area byte by byte. Assembled bytes of data are stored in successive memory location until all values are stored . ORG 2000H DATA : DB 20H, 30H, 40H,50H DW (define word):- this instruction is used to assign a 16 bit values to two memory location. ORG 7000H , START DW 4AC2H END :-This directive indicates that the end of source program . END [< operand spec >]

The optional < operand spec > indicates the address of the instruction where the execution of the program should begin . START :- This directive indicates that the first word of the target program generated by the assembler should be placed in the memory word with address <constant >. START < constant >

NISHIT KACHIYA

Page 24

SYSTEM SOFTWARE
6) Distinguish between single pass and two pass assembler. In your opinion, which is preferred ? give reason .
An assembler which goes through an assembly language program only once is known as one-pass assembler. An, assembler which goes through an assembly language program twice, is called two pass assembler . A one pass assembler passes over the source file exactly once, in the same pass collecting the labels , and doing the actual assembly . A two pass assembler does two passes over the source file . In the first pass all it looks for label definitions and introduces them in the symbol table. In the second pass, after the symbol table is complete, it does the actual assembly by translating the operations and so on. Pass one uses three data structures : OPTAB , SYMTAB and LITTAB . whereas pass two data structure uses________________________________. The entire translation of assembly language program into one object program is done in only one pass . The two pass assemblers are widely used and the translation process is done in two passes . The assembler suffers the problem of forward reference . handling the forward reference in single pass is difficult. The object code can be produced in the single pass assemblers in two different ways. In the first way the object code is directly loaded into the main memory for execution. In the second way the object program is stored in the secondary memory. This object program will be loaded in the main memory for execution whenever necessary . In Two-pass assembler , During the first pass it collects all labels. And during the second pass it produce the machine code for each instruction and assign address to each of them . it assign addresses to labels by counting their position from the starting address. The forward reference problem is also handled to some extent in single pass assemblers. The assembler scans the source assembly language program, instruction by instruction and translate them into machine codes. If there is an instruction which has a forward reference, the assembler leaves the address of that particular symbol and proceeds further. This symbol is entered in symbol table and marked as undefined. When the symbol definition is encountered the assembler inserts the address in the symbol table. The assembler also insert the address to the instructions, which

NISHIT KACHIYA

Page 25

SYSTEM SOFTWARE
use this symbol in the list of forward references. This is how the forward reference problem is handled in pass one assembler . The forward reference problem is conveniently handled in two pass assemblers. If undefined symbols are encountered after reaching the end of the statement, then the assembler generates the error messages. One pass assembler is faster because it scans the program only once , it does not have many features supported by two pass assemblers. Where two pass provides many features than the one pass assembler . so it is widely used .

7) Compare and Contrast manually VARIANT-I and VARIANT-II of intermediate code generated by pass-I of the assembler .
We consider two variants of intermediate code which is different in the information contained in their operand fields .

VARIANT-I :- The first operand is represented by a single digit number which is a code for a register. The second operand, which is a memory operand, which is represented bye the form ( operand class, code) Where operand class is one of the Constant , Symbol and Literal .for a constant, the code field contain the internal representation of the content itself. For example, the operand descriptor for the statement START 200 is(C, 200) .For a symbol or literal, the code field contain the ordinal number of the operands entry in SYMTAB or LITTAB. START READ LOOP 200 A (AD,01) (IS,09) (IS,04) (IS,02) (C,200) (S,01) (1)(S,01) (1)(L,01) (DL,05)

MOVER AREG, A SUB LTROG AREG,=1

NISHIT KACHIYA

Page 26

SYSTEM SOFTWARE
An entry is made in SYMTAB only when symbol occurs in the label field of an assembly statement, e.g. an entry (A,345,1) if symbol A is allocated one word at address 345 . while processing a forward reference MOVER AREG , A

It is necessary to enter A in SYMTAB . at this point, the address and length field of As entry cant be filled .this implies that two kind of entries may exist in SYMTAB at anytime for defined symbols and for forward references . VARIANT-II :- This variant is different from variant-I in that the operand fields of the source statements are replaced by their processed forms . for declarative statements and assembler directives, processing of the operand fields is essential to support LC processing. Hence these forms contain the processed forms. Literals are entered in LITTAB and are represented as (L,m) in IC. START READ LOOP 200 A (AD,01) (IS,09) (IS,04) (IS,02) (C,200) A AREG, A AREG (L,01) (DL,05)

MOVER AREG, A SUB LTROG AREG,=1

Comparison of the Variants : Variant I of the intermediate code appears to require extra work in pass I since operand fields are completely processed. The function of pass II are quite trivial . To process the operand field of a declaration statement, we need to refer appropriate table and obtain the operand address. Most declaration do not require any processing, e.g. DC, DS and START statements, while some declaration require processing, e.g. LTROG. Variant II reduces the work of pass I by transferring the burden of operand processing from pass I to pass II of the assembler .the IC is less compact . On the other hand, by making pass II to perform more work, the function and memory requirements of the two passes get balanced.

NISHIT KACHIYA

Page 27

SYSTEM SOFTWARE
Pass I Data structure Work area Pass II |||||||||||||||||||||||||||| Data structure Work area Work area ||||||||||||||||||||||||||| Pass II Data structure Data structure Work area ||||||||||||||||||||||||||| Pass II

Variant I

Variant II

Variant II is well suited if expressions are permitted in the operand fields of an assembly statements .

8) How link list and Hash table data structures are used in generation of symbol table ? Explain .
The symbol tables are most important data structures in the design of the translators like Compilers and Assemblers. The symbol table maintain the attributes of the symbols used in the source program . the maintenance of the symbol table is called symbol table management. It is also called book keeping . There can be a separate entry for each entity . the names can be stored in the symbol table using fixed size arrays or dynamically using pointers . the data structures for symbol tables can be : 1. Linked list 2. Hash Tables Linked List :- This data structure is used to implement the symbol table in a simple way . the symbol table keeps the names and their attributes . If new name is encountered that also be considered.

Name Attributes Name Attributes 2 2 3 3 Each name and its attributes can collectively be considered as a separate entity . these entities can be made available in a list . the end of the list is left opened to add new symbols . Hash Tables :- This data structure can also be used to implement the symbol table . open hashing technique is used in symbol table, where open refers to no limit .
NISHIT KACHIYA Page 28

Name

Attributes 1

SYSTEM SOFTWARE
In the implementation of symbol table hashing table can be used , the data structure will have : 1. Pointers to symbol table entries 2. Symbol table entries for names The pointers will point the names in symbol table entries. These are headers to the names. These are obtained by the hash function. The list can be dynamically maintained. P1 P2 P3 P4 P5 . . . .

This type of data structure has better performance over the list in handling the operations like searching, insertion and queries .

9) Explain Synthesis Phase and Analysis Phase of an assembler .


Synthesis Phase :- The fundamental information requirements arise in the synthesis phase of an assembler . o Consider the assembly statement MOVER BREG , ONE The first item of the information depends on the source program. Hence it must be available by analysis phase . the second item of information does not depend on the source program, it merely depends on the assembly language . Synthesis phase can determine this information for itself. Two data structures are placed during the synthesis phase : 1. Symbol table 2. Mnemonic table Each item of the symbol table has two primary fields- name and address . The table is built by the analysis phase. An entry in the mnemonic table has two primary fields mnemonic and opcode . The synthesis phase uses these tables to obtain the machine address with which a name is associated .

NISHIT KACHIYA

Page 29

SYSTEM SOFTWARE
Analysis Phase :-The primary function performed by the analysis phase is the building of the symbol table .it must determine the addresses with which the symbolic name used in a program are associated . It is possible to determine some addresses directly .To implement memory allocation a data structure called location counter (LC) is introduced .it contain the address of the next memory word in the target program . it is initialized to the constant specified in the START statement .

10 ) Explain the term Forward Reference with the help of Example .

NISHIT KACHIYA

Page 30

SYSTEM SOFTWARE CHAPTER :-5


1) Define macro. Explain the process of macro expansion for Assembly language program with a suitable example.
A macro is a unit of specification for program generation through expansion . A macro consist of a name , a set of formal parameters and a body of code generated from its body. This is called macro expansion . A macro call leads to macro expansion. During macro expansion, the macro call statement is replaced by a sequence of assembly statements. To differentiate between the original statements of a program and the statements resulting from macro expansion, each expanded statement is marked with a + preceding its label field. Two key notation concerning macro expansion are : Expansion time control flow : This determines the order in which model statements are visited during macro expansion. Lexical substitution: Lexical Substitution is used to generate an assembly statement from a model statement . Various data structures can be used to perform macro expansion : APTAB EVTAB MEC APTAB_ptr EVTAB_ptr Actual parameter table EV table Macro expansion counter APTAB pointer EVTAB pointer

2) Explain macro definition & macro call with example ?


A macro definition is given below : Macro Definition :- A macro definition is enclosed between a macro header statement and a macro end statement. Macro definitions are located at the start of a program. A macro definition consist of :1. A macro prototype statement 3. Macro preprocessor statement 2. One or more model statement

NISHIT KACHIYA

Page 31

SYSTEM SOFTWARE
The macro prototype statement declares the name of a macro and the names and kind of its parameters. A model statement is a statement from which an assembly language statement may be generated during macro expansion . A preprocessor statement is used to perform auxiliary functions during macro expansion . The macro prototype statement has following syntax : < macro name > [<formal parameter spec > [,..]] Where < macro name > appears in the mnemonic field of an assembly statement . Statements present in macro definition : Two assembler directives (MACRO and MEND) are used in macro dominions. The first MACRO statement identifies the beginning of a macro definition. Symbol in the label field is the name of the macro. Entries in the operand field identify the parameters of the macro instruction. The MEND assembler directive marks the end of the macro definition. Macro Call :- A macro is called by writing a macro name in the mnemonic field of an assembly statement. The macro call has the syntax : < macro name > [< actual parameter spec > [,]] Where an actual parameter typically resembles an operand specification in an assembly language statement . Example :MACRO INCR MOVER ADD MOVEM MEND

&MEM_VAL, &INCR_VAL, &REG %REG, &MEM_VAL &REG, %INCR_VAL &REG, &INCR_VAL

MACRO and MEND are the macro header and macro end statements. The prototype statement indicates that three parameters called MEM_VAL, INCR_VAL, and REG exist for the macro . Statements with the operation codes MOVER, ASS and MOVEM are model statements .

NISHIT KACHIYA

Page 32

SYSTEM SOFTWARE
3) What do you mean by nested macro ? how to call nested macro explain with an example ?
A Model statement in a macro may constitute a call on another macro. Such calls are known as nested macro calls. in the nested macro call , the call is done by outer macro and the macro called is the inner macro . Expansion of nested macro calls follows the last-in-first-out (LIFO) rule . in a structure of nested macro calls, expansion of the latest macro call is completed first .

NISHIT KACHIYA

Page 33

SYSTEM SOFTWARE
4) What is the difference between macro and subroutines? Explain.
(1) Macros are pre processor directives i.e. it is processed before the source program is passed to the compiler. Subroutines are blocks of codes with a specific task, to be performed and are directly passed to the compiler. (2) In a macro call the pre processor replaces the macro template with its macro expansion, in a literal way. As against this, in a function call the control is passed to a function along with certain arguments, some calculations are performed in the function and a useful value is returned back from the function. (3) Macro increases the program size. For example, if we use a macro hundred times in a program, the macro expansion goes into our source code at hundred different places. Whereas, functions make the program smaller and compact. For example, if a function is used, even if it is called from hundred different places in the program, it would take the same amount of space in the program. (4) Macros make the program run faster as they have already been expanded and placed in the source code before compilation. Whereas, passing arguments to a function and getting back the returned values does take time and would therefore slow down the program.
(5) The statements that form the body of the macro are generated each time a macro is

expanded. Statements in a subroutine appear only once, regardless of how many times the subroutine is called.

5) Differentiate between Positional parameter & keyword Parameter .


In positional parameter there is one to one correspondence between macro definition and macro call . the calling sequence should be same as defined sequence . For example :- let us say a,b,c are the parameters in jobcard correct: jobname job a,b,c incorrect : jobname job b,a,c
NISHIT KACHIYA Page 34

SYSTEM SOFTWARE
In Keyword Parameter sequence is not important and number of parameters used while calling the macro are also not important . In positional parameter programmer must be careful to specify the arguments in the proper order . In keyword parameter , each parameter name is followed by = sign . After the equal sign , a default value is specified for some of the parameters. A positional parameter is written as &<parameter name >. E.g. &SAMPLE , where SAMPLE is the name of the name parameter . The value of the positional Formal parameter XYZ is determined by the rule of positional association as follows: 1. Find the ordinal position of XYZ in the list of formal parameter in the macro prototype statement. 2. Find the actual parameter specification occupying the same ordinal position in the list of actual parameters in the macro call statement. For keyword parameters, < parameter name > is an ordinary string and < parameter kind> is the string = in syntax rule . The value of the keyword Formal parameter XYZ is determined by the rule of keyword association as follows: 1. Find the actual parameter specification which has the form XYZ= < ordinary string > This is very useful in situation where long list of parameters have to be used.

6) Why macro is used? Explain two types of expansion method . OR Compare and contract lexical and semantic expansion of a macro. Also explain expansion time variable taking suitable example.

Macros are used to provide a program generation facility through macro expansion .
Many language provide built-in facilities for writing macros. The two types of expansion are : 1. Lexical Expansion 2. Semantic Expansion

NISHIT KACHIYA

Page 35

SYSTEM SOFTWARE
Lexical Expansion :- Lexical Expansion implies replacement of a character string by another character string during program generation. It is generally used to replace occurrences of formal parameters by corresponding actual ones . Semantic Expansion :- Semantic Expansion implies generation of instructions build to the requirements of a specific usage. It can be achieved by a combination of advanced macro facilities like AIF, AGO statements and expansion time variables. It is characterized by the fact that different uses of a macro can lead to codes which is different in the number, sequence and opcode of instruction . Expansion time variables :- Expansion time Variables (EVs) 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 all macro calls situated in a program and can be used in any macro which has a declaration for it . LCL < EV specification > [, < EV specification > ] GBL <EV specification > [,< EV specification> ] and < EV specification > has the syntax & < EV name > , where < EV name > is an ordinary string . Example :MACRO CONSTANT LCL SET DB SET DB MEND

&A &A

&A 1 &A &A+1 &A

A call on macro CONSTANTS is expanded as follows : the local EV A is created. The first SET statement assign the value 1 to it .

7) Define the data structures used in the one pass macro processor algorithm.
There are three Data structures used in one pass macro processor .
1. 2. 3.

DEFTAB Macro definition table NAMTAB Macro name table ARGTAB Parameter values table

DEFTAB: which contains the macro prototype and the statements that make-up the macro body.
NISHIT KACHIYA Page 36

SYSTEM SOFTWARE
NAMTAB: which contains the macro names and pointers to the beginning and end of the macro definition in DEFTAB. ARGTAB: which contains the argument values of the respective parameter included in the macro prototype statement.

8) Explain the macro Expansion and Conditional Macro Expansion.


Macro Expansion :- macro call leads to macro expansion. During macro expansion, the macro call statement is replaced by a sequence of assembly statements. To differentiate between the original statements of a program and the statements resulting from macro expansion, each expanded statement is marked with a + preceding its label field. Two key notation concerning macro expansion are : Expansion time control flow : This determines the order in which model statements are visited during macro expansion. Lexical substitution: Lexical Substitution is used to generate an assembly statement from a model statement . Conditional Macro Expansion :- While writing a general purpose macro, it is important to ensure execution efficiency of its general code . Conditional macro expansion helps in generating assembly code suited to the parameters in a macro call . this is achieved by ensuring that a model statement is visited only under specific condition during the expansion of a macro. The AIF and AGO statements are used for this purpose . For example : It is required to develop a macro EVAL such that a call EVAL A, B, C Generates efficient code to evaluate A-B+C in AREG . when the first two parameters of a call are identical, EVAL should generate a single, MOVER instruction to load the 3rd parameter into AREG .

9) Explain the pass structure of macro-assembler in details.


To design the pass structure of a macro-assembler we identify the functions of a macro preprocessor and the conventional assembler which can be merged to advantage. Pass I 1. Macro definition processing 2. SYMTAB construction
NISHIT KACHIYA Page 37

SYSTEM SOFTWARE
Pass II 1. 2. 3. 4. Pass III 1. Target Code generation Pass II is large in size since it performs many function . all the data structures of the macro preprocessor needs to exit during this pass . Macro expansion Memory allocation Processing of literals Intermediate code generation

NISHIT KACHIYA

Page 38

SYSTEM SOFTWARE CHAPTER :-6


1) What is memory allocation? Discuss its types in details.
Memory allocation involves three important tasks : 1. Determine the amount of memory required to represent the value of a data item. 2. Use an appropriate memory allocation model to implement the scope of data. 3. Determine appropriate memory mapping to access the values in a non scalar data item. E.g. values in an array. Types of Memory Allocation :1) Static memory allocation 2) Dynamic memory allocation Dynamic Binding :- A memory binding is an association between the memory address attributes of data item and the address of memory area. Memory allocation is the procedure used to perform memory binding . Memory binding can be dynamic or static in nature . In static memory allocation , memory is allocated to a variable before the execution of a program begins .
Static memory allocation is performed during compilation. No memory allocation OR deallocation actions are performed during the execution of a

program . In dynamic memory allocation, memory bindings are established and destroyed during the execution of a program . typical examples of the use of these memory allocation models are FORTRAN for static allocation and block structured language like PL/L , pascal etc. for dynamic allocation . Dynamic memory allocation has two flavors : 1. Automatic allocation 2. Program controlled allocation In automatic dynamic allocation , memory is allocated to the variables declared in a program unit is entered during execution and is deallocated when the program unit is exited.
NISHIT KACHIYA Page 39

SYSTEM SOFTWARE
Thus the same memory area may be used for the variable of different program unit . It is also possible that different memory area may be allocated to the same variable in different activations of a program unit . In program controlled dynamic allocation , a program can allocate or deallocate memory at arbitrary points during its execution.

(a)

(b)

(c)

(d)

It is obvious that in both automatic and program controlled a l l o c a t i o n a d d r e s s o f t h e memory area allocated to a program unit cannot be determined at compilation . Dynamic memory allocation is implemented using stack and heap .This tends to make it slower in execution than static memory allocation . Automatic dynamic memory allocation is implemented using stack since entry and exit from program units is LIFO in nature. Program controlled dynamic allocation is implemented using a heap. Dynamic allocation provides some advantages. Recursion can be implemented easily because memory is allocated which a program unit is entered during execution. Dynamic allocation can also support data structures whose size are determined dynamically , e.g. an array declaration A[m,n] , where m and n are variables .

2) Explain analysis phase and synthesis phase of compiler .


There are two phases of compiler . 1. Analysis Phase 2. Synthesis Phase

NISHIT KACHIYA

Page 40

SYSTEM SOFTWARE
Analysis Phase :- Analysis breaks the source program into constituent pieces and
creates intermediate representation . the analysis part can be divided along the following phases : 1. Lexical Analysis : the program is considered as a unique sequence of characters. The lexical analyzer reads the program from left-to-right and sequence of characters is grouped into tokens 2. Syntax Analysis : The syntax analysis is also called parsing. Tokens are grouped into grammatical phrases represented by a parse tree , which gives a hierarchical structure to the source program . 3. Semantic Analysis : the semantic analysis phase checks the program for semantic errors and gathers type information for successive parser . Type checking check types of operands.

Synthesis Phase :- generates the target program from the intermediate


representation. The synthesis part can be divided along the following phase . 1. Intermediate Code Generation :- An intermediate code is generated as a program for an abstract machine . the intermediate code should be easy to translate into the target program . 2. Code Optimizer :- this phase attempts to improve the intermediate the intermediate code so that faster-running machine code can be obtained . 3. Code Generator :- this phase generates the target code consisting of assembly code :

3) What are the various types of descriptors? explain with example.


There are two types of descriptors . 1. Operand descriptor 2. Register descriptor Operand Descriptor :- Operand descriptor is used to maintain the type , length and addressability information for each operand. A Partial result is the value of some sub expression computed while evaluating an expression. An operand descriptor has the following fields : Attributes: It contain the subfield type & length . Addressability: It specifies where the operand is located and how it can be accessed. It has two fields .
NISHIT KACHIYA Page 41

SYSTEM SOFTWARE
Addressability code : It Takes the values M(operand is in memory) and R(operand is in register) . Address: It contain the address of a CPU register or memory word . An operand descriptor is built for every operand participating in an expression . i.e. for ids , constants and partial results. A descriptor is built for an id when the id is reduced during parsing. For example :- the code generated for the expression a*b is as follows : MOVER MULT AREG, A AREG, B

Three operand descriptors are used during code generation . Assuming a,b to be integers occupying 1 memory word, these are :

(int, 1) (int, 1) (int, 1)

M, addr(a) M,addr(a) R,addr(AREG)

Descriptor for a Descriptor for b Descriptor for a*b

Register Descriptor :- A register descriptor has two fields : Status : it contain the code free or occupied to indicate register status . Operand descriptor : If status = occupied, this field contain the descriptor # for the operand contained in the register . Register descriptors are stored in an array called Register descriptor . For example :- the register descriptor for AREG after generating code for a*b would be Occupied #3

This indicates that register AREG contains the operand described by descriptor #3.

NISHIT KACHIYA

Page 42

SYSTEM SOFTWARE
4)Compare and contrast the following parameter passing mechanism in terms of execution efficiency and power to produce side effects. 1. 2. 3. 4. Call by value Call by value-result Call by reference Call by name

The description of above parameters are given below. Call by Value :- in this mechanism the value of the actual parameters are passed to the called function .these values are assigned to the corresponding formal parameters .If a function changes the value of parameter, the change is not reflected on the corresponding formal parameters . Call by value is commonly used for built in function of the language .its main advantage is its simplicity . A called function may allocate memory to a formal parameter . the compiler can treat formal parameter as a local variable . Call by value Result :- This mechanism extends the capabilities of the call by value mechanism by copying the value of formal parameters back into corresponding actual parameters at return . this mechanism inherits the simplicity of the call by value mechanism but incur higher overheads. Call by Reference :- In this mechanism the address of the actual parameter is passed to the called function. If the parameter is an expression, its value is computed and stored in a temporary location and the address of the temporary location is passed to the called function. If the parameter is an array element, its address is similarly computed at the time of call . this mechanism is very popular because it has cleaner semantics than call by value result . For example :Function alpha (a , b : integer) : integer; Z := a; I := i+1 ;

B := a+5 ; Return
NISHIT KACHIYA Page 43

SYSTEM SOFTWARE
End alpha ; Where z, I are non local variables of alpha. Call by Name :- It has the same effect as if every occurrence of a formal parameter in the body of the called function is replaced corresponding actual parameter .the actual parameter corresponding to a formal parameter can change dynamically during the execution of a function . this makes the mechanism call by name powerful.

5) What is Code Optimization? Explain its types in details .


Code optimization aims at improving the execution efficiency of a program . this is achieved in two ways : Redundancies in a program are eliminated and computations in a program are rearranged to make it execute efficiency . Commonly used optimizing transformations are : Compile time Evaluation :- Execution efficiency can be improved by performing certain action specified in a program during compilation itself . Constant Folding is the main optimization of this kind . when all operands in an operation are constants, the operation can be performed at compilation time . For example :- a : = 3.14157/2 can be replaced by a : = 1.570785 eliminating a division operation . Elimination of Common Sub expressions:- Common sub expressions are occurrences of expressions holding the same value . such expression are called equivalent expressions .

For example :- a : = b*c x : = b*c + 5.2 ==> a:=t;

t : = b*c ;

x : = t + 5.2 ; Here CS , contains the two occurrences of b*c. the second occurrences of b*c can be eliminated because the first occurrences of b*c is always evaluated before the second occurrence is reached during execution of the program . Dead Code Elimination :- A code which can be omitted from a program without affecting is result is called dead code . Dead code is detected by checking whether the value assigned in an assignment statement is used anywhere in the program . For example :- An assignment x : = < exp > constitutes dead code if the value assigned to X is not used in the program .
NISHIT KACHIYA Page 44

SYSTEM SOFTWARE
Frequency Reduction :- Execution time of a program can be reduced by moving code from a part of a program which is executed very frequently to another part of a program which is executed fewer time . For example :For i := 1 to 100 do begin z := i; x := 25*a; y :=x+z ; end; here x := 25*a ; is loop invariant . Strength Reduction :- The strength reduction replaces the occurrence of a time consuming operation by an occurrence of a faster operation . strength reduction is very important for array accesses occurring within program loops . end ; ==> x := 25*a ; for i := 1 to 100 do begin z := i; y := x+z;

6) Explain the difference between Local Optimization and Global Optimization.


Local Optimization :- The optimizing transformations are applied over small segments of a program consisting of a few segment . The benefits are limited because certain optimizations e.g. loop optimization are beyond the scope of local optimization. Basic block :- A basic block is a sequence of program statements (s1, s2,.Sn) such that only Sn can be a transfer of control statement and only S1 can be the destination of a transfer of control statement . Local optimizing is performed by the front end while converting a source program into IR. Local optimization also simplifies certain aspects of global optimization. Local optimization provides limited benefits at a low cost. The scope of local optimization is a basic block. The cost of local optimization is low because the sequential nature of the basic block simplifies the analysis needed for optimization.

NISHIT KACHIYA

Page 45

SYSTEM SOFTWARE
Global Optimization :- The optimizing transformations are applied over a program unit, i.e. over a function or a procedure. Compared to local optimization , global optimization requires more analysis efforts to establish the feasibility of an optimization .

7) Explain the difference between pure interpreter and impure interpreter.


The schematic of Source program is called a pure interpreter . the source program is retained in the source from all through its interpretation. This arrangement incurs substantial analysis overheads while interpreting a statement. An impure interpreter performs some processing of the source program to reduce the analysis overhead during interpretation. The preprocessor converts the program to an intermediate representation (IR) which is used during interpretation . DATA Interpreter data

SP

Preprocessor

Interpreter

Result

Example :- Postfix notation is a popular intermediate code for interpreters. The intermediate code for a source string a + b*c could look like the following :

S#17

S#4

S#29

Where each IC unit resembles a token .

8) Discuss the compilation of the expression in details and also give various steps in the code generation of the Expression .
The major issues in code generation for expression are as follows : 1. Selection of the instructions to be used in the target code. 2. Use of register and handling of partial results.
NISHIT KACHIYA Page 46

SYSTEM SOFTWARE
The evaluation order of operators depends on operator precedences . There are two types of descriptors . 1. Operand descriptor 2. Register descriptor Operand Descriptor :- Operand descriptor is used to maintain the type , length and addressability information for each operand. A Partial result is the value of some subexpression computed while evaluating an expression. An operand descriptor has the following fields : Attributes: It contain the subfield type & length . Addressability: It specifies where the operand is located and how it can be accessed. It has two fields . Addressability code : It Takes the values M(operand is in memory) and R(operand is in register) . Address: It contain the address of a CPU register or memory word . An operand descriptor is built for every operand participating in an expression . i.e. for ids , constants and partial results. A descriptor is built for an id when the id is reduced during parsing. For example :- the code generated for the expression a*b is as follows : MOVER MULT AREG, A AREG, B

Three operand descriptors are used during code generation . Assuming a,b to be integers occupying 1 memory word, these are :

(int, 1) (int, 1) (int, 1)

M, addr(a) M,addr(a) R,addr(AREG)

Descriptor for a Descriptor for b Descriptor for a*b

Register Descriptor :- A register descriptor has two fields :


NISHIT KACHIYA Page 47

SYSTEM SOFTWARE
Status : it contain the code free or occupied to indicate register status . Operand descriptor : If status = occupied, this field contain the descriptor # for the operand contained in the register . Register descriptors are stored in an array called Register descriptor . For example :- the register descriptor for AREG after generating code for a*b would be Occupied #3

This indicates that register AREG contains the operand described by descriptor #3.

9) What are the various task involves in memory allocation process.


Automatic dynamic allocation is implemented using the extended stack model . each record in the stack has two reserved pointers instead of one . each stack record accommodates the variable for one activation of a block , hence we call it an activation record (AR). The following notation is used to refer to the activation record of a block .

During the execution of a block structured program , a register called the activation record base (ARB) always points to the start address of the TOS record .this record belongs to the block which contain the statement being executed . Dynamic Pointer :-The first reserved pointer in a blocks AR points to the activation record of its dynamic parent . this is called dynamic pointer and has the address 0(ARB). The dynamic pointer is used for allocating AR.

NISHIT KACHIYA

Page 48

SYSTEM SOFTWARE

X : real ; A B y: char; C z ,w : integer ; Z : = 10; X:= z ;

Action at block entry : NO. 1. 2. 3. 4. 5. 6. TOS TOS ARB TOS TOS* TOS := := := := := := Statement TOS + 1 ; ARB ; {set the dynamic pointer } TOS ; TOS + 1 ; ; { set reserved pointer 2} TOS + n ;

Static Pointer :- Access to nonlocal variables is implemented using the second reserved pointer in AR, which has an address 1(ARB) , is called static pointer .when AR is created for block b , its static pointer is set to point to the AR of the static ancestor of b. for large values of level difference , it is expensive to access nonlocal variable using static pointer .

10 ) Explain the term Triples and Quadruples .


Triples :- A Triple is a representation of an elementary operation in the form of a pseudo-machine instruction . it is also a record structure used to represent the three address codes, which has only three fields : Operator
NISHIT KACHIYA

Operand 1

Operand 2
Page 49

SYSTEM SOFTWARE
Triples are number in some convenient manner . Each operand of a triple is either a variable / constant . in the later case , the operand field contains that triples number . The triple representations are :

OPERATOR (0) (1) + *

OPERAND 1 I (0)

OPERAND 2 I K

A program representation called indirect triples is useful in optimizing compilers . Quadruples :- A quadruple is a record structure used to represent three- address codes with four fields : Operator Operand 1 Operand 2 Result name

Here , result name designates the result of the evaluation . Example :The expression is i = i + j + k The three address codes are : t1 : = i + j Ii : = t1 + k (where t1 ia a temporary variable) The quadruples representations are : OPERATOR (0) (1) + * OPERAND 1 i T1 OPERAND 2 J K RESULT t1 I

NISHIT KACHIYA

Page 50

SYSTEM SOFTWARE
11) What is control structure ? give details of the parameters passing mechanism.
The control structure of the programming language is the collection of language features which govern the sequencing of control through a program . The control structure of a PL consists of control transfer , conditional execution , iteration control and procedure call . Parameter passing mechanism : Call by Value :- in this mechanism the value of the actual parameters are passed to the called function .these values are assigned to the corresponding formal parameters .If a function changes the value of parameter, the change is not reflected on the corresponding formal parameters . Call by value is commonly used for built in function of the language .its main advantage is its simplicity . A called function may allocate memory to a formal parameter . the compiler can treat formal parameter as a local variable . Call by value Result :- This mechanism extends the capabilities of the call by value mechanism by copying the value of formal parameters back into corresponding actual parameters at return . this mechanism inherits the simplicity of the call by value mechanism but incur higher overheads. Call by Reference :- In this mechanism the address of the actual parameter is passed to the called function. If the parameter is an expression, its value is computed and stored in a temporary location and the address of the temporary location is passed to the called function. If the parameter is an array element, its address is similarly computed at the time of call . this mechanism is very popular because it has cleaner semantics than call by value result . For example :Function alpha (a , b : integer) : integer; Z := a; I := i+1 ;

B := a+5 ; Return
NISHIT KACHIYA Page 51

SYSTEM SOFTWARE
End alpha ; Where z, I are non local variables of alpha. Call by Name :- It has the same effect as if every occurrence of a formal parameter in the body of the called function is replaced corresponding actual parameter .the actual parameter corresponding to a formal parameter can change dynamically during the execution of a function . this makes the mechanism call by name powerful.

12) How the non local variables are accessed ? explain with proper example .

13) Give the Difference between assembler , compiler and interpreter .


An assembler is the translator for an assembly language of a computer. An assembly language is a low-level programming language which is peculiar to a certain computer. A compiler is a translator for machine independent HLL like say FORTRAN,COBOL etc. An interpreter analysis the source program statement by statement and it self carries out the actions implied by each statement.
NISHIT KACHIYA Page 52

SYSTEM SOFTWARE

CHAPTER :-7, 8
1) What are Editors ? Explain various types of editors.
Editing is the process of selecting and preparing language, images, sound, video, or film through processes of correction, condensation, organization, and other modifications in various media. A person who edits is called an editor. In other way , the editor is a program , which allows creating a file, which can contain C program, C++ program, assembly language program etc. it allows modifying and updating of the file . these all are word processing software. There are many types of editors , but they fall into two general categories : 1. Line editors 2. Full screen editors Line Editors :- There are two definitions for line editor. Early computer programs used a line editor program, which evaluated the lines and caught mistakes. Typically, however, the term line editor stands for a copy editor who specifically reads a text line by line. This type of editing requires word for word reading of a text, and a very good sense of proper grammar and usage. The line editor may make comments to improve readability and change any grammatical mistakes or spelling errors. The line editor is more frequently called a copy editor, since directly reading and editing copy is the most important function. the line editor must also evaluate the text for consistency. For example, a line editor might evaluate the dates in a text to be certain that all dates are consistent. The line editor might also research and check the facts in a document to be certain that all facts are accurate. Full-Screen Editors :- A computer program that allows the user to work with the computer in an interactive manner by using most of the area of a cathode-ray tube or similar electronic display. Example Microsoft Word

In full screen editor they are supported by macro support.


Page 53

NISHIT KACHIYA

SYSTEM SOFTWARE
It is supported by more memory space as compared to other window editor Full screen editor doesnt support multiple window. Full screen editor feature on single window .

2) What is a Text editor? Explain various types of text editor ?


A text editor is a simple computer program which allows users to create, change, or edit plain text files. Text editors can be used for creating computer programs, editing the source code of programming languages, editing (HTML), and creating web pages . They are most commonly used today for programming purposes, rather than creating documents. There are different types of text editors : 1. 2. 3. 4. 5. Line editors Stream editors Screen editors Word processors Structure editors

Line Editors :- the scope of edit operation in line editor is limited to a line of text . the line is designated positionally. The primary advantage of line editor is its simplicity . Advantages: Simple for read and write Simple in design and implementation Disadvantages:Not user friendly only single line is used for editing Stream Editors :- A stream editors views the entire text as a stream of characters. Stream editors typically supports character , line and context oriented commands. Line and stream editors typically maintain multiple representation of text . Screen Editors :- A screen editors uses the what-you-see-is-what-you-get principle in editor design . the editor displays a screenful of text at a time . the user can move the cursor over the screen , position it at the point where he desires to perform
NISHIT KACHIYA Page 54

SYSTEM SOFTWARE
some editing. It is possible to see the effect of an edit operation on the screen. This is very useful while performing the text to produce printed documents. Word Processor :- Word processors are basically document editors with additional features to produce well formatted hard copy output . Essential features of word processors are command for moving sections of text from one place to another , merging of text and searching and replacement of words . many word processors support spell-check option. WordStar is a popular editor of this class . Structure Editors :- A structure editor incorporates an awareness of the structure of a document . this is useful in browsing through a document. E.g. If a programmer wishes to edit a specific function in a program file . the structure is specified by the user while creating the document . A special class of structure editors called Syntax directed editors are used in a programming environment .

3) What are the Features of text editors ?


There are different features of text editors . Search and replace :-the process of searching for a word or a string in a text file and optionally replacing the search string with a replacement string . Cut, Copy and Paste :- most text editors provide methods to duplicate and move text within the file or between files. Text formatting :- Text editors often provide text editing features like line wrap , comment formatting etc. Undo and Redo :- As with word processors , text editors will provide a way to undo and redo . with older text editors , there is only one level of edit history . Importing :- reading the content of another text file into the file currently being edited . some text editors provide a way to insert the output of a command issued to the operating systems shell . Filtering :- Some advanced text editors allow you to send all or section of the file being edited to another utility and read the result back into the file in place of the line being filtered .

NISHIT KACHIYA

Page 55

SYSTEM SOFTWARE
4) What do you mean by object module? explain all the components that are present in object module .
The object module of a program contain all the information necessary to relocate and link the program with other program . the object module of a program P consist of 4 components : Header :- the header contain translated origin size and execution start address of P . Program :- this component contains the machine language program corresponding to P. Relocation Table :- (RELOCTAB) this table describes IRR(Instruction Requirity Relocation)p . each relocation table entry contain a single field . Translated address : translated address of an address sensitive instruction . Linking Table :- (LINKTAB) this table contain the information concerning the public definitions or external reference . Each LINKTAB entry contain three fields : Symbol :- Symbolic name Type :- indicate whether public definition or external reference Translated address :- For a public definition , this is the address of the first memory word allocated to the symbol . For an external references , it is the address of the memory word which is required to contain the address of the symbol .

5) Give the difference Between Linker and Loader .


The loader is the program that loads the object program from the secondary memory into main memory for execution of the program . The linker is the program that links all the object module of program . The main difference between linker and loader are stated below : Loader : 1. Main task of loader is to load a source program into memory and then prepare it for further executions. 2. The type of loader includes absolute loader , relocating and dynamic linking loaders.
NISHIT KACHIYA Page 56

SYSTEM SOFTWARE
3. Loader provides the allocation of memory for programs. 4. It loads the modules and libraries for further execution. 5. The loader can perform the linking function. Linker : 1. The purpose of the linker is to link all object module programs and necessary libraries . 2. There are two types of linker. Static and dynamic. 3. It links only different object module of that programs . 4. It only links modules and libraries for further execution. 5. It is actually a part of loaders function.

6) What is Debuggers ? explain it types in detail.


Debuggers are the system programs that are used to debug the input program . it helps the system programmers to search for bugs in program and correct all of them . In addition to this , debugging is the process to find and remove errors or bugs available in the program .it means that particular program can be debugged step wise. There are two types of debugging techniques : 1. Single step control method 2. Break point method Single Step Control Method :- In single step control method , the user can check out contents of the register , memory and variables after executing each step of program . it helps the programmer to find the bugs and remove all of them , statement by statement . This method is used only for small size program codes . it is time consuming and not suited for longer program. This method cannot find timing errors and errors in direct memory access. Break Point Method :- The break point method allows user to set a break point in a program to check the contents of register , memory , and variables . the program execution is halted at the break point , for user to evaluate for intermediate result during execution . it also helps to localize the errors and to skip the code that is error free .

NISHIT KACHIYA

Page 57

SYSTEM SOFTWARE
7) What is overlay? What is overlay structured program ? Give proper example. OR What do you mean by overlay and overlay structured programs?
An overlay is a part of a program which has the same load origin as some other parts of the program . Overlays are used to reduce the main memory requirement of a program . Overlay structured programs : A overlay structured program consist of 1. A permanently resident portion , called root . 2. A set of overlays. Execution of an overlay structured program proceeds as follows : To start with the root is loaded into memory and given the control for the purpose of execution. Other overlays are loaded whenever necessary . this reduce the memory requirement of a program . it is also possible to execute programs whose size exceeds the amount of memory which can be allocated to them . The overlay structure of a program is designed by identifying mutually exclusive modules- that is modules which do not call each other. Such modules do not reside in memory . Hence , they are located in different overlays with the same load origin. Example :- Consider a program with six sections named init , read , trans_a , trans_b , trans_c , and print . Init performs some initialization and passes control to read . read reads one set of data. Trans_a, trans_b and trans_c are mutually exclusive . they can be made into separate overlays. Read and print are put in the root of the program since they are needed for each set of data .

NISHIT KACHIYA

Page 58

SYSTEM SOFTWARE

8) Difference between Non relocatable programs ,Relocatable programs

and self-relocating programs.


A non relocatable program is a program which cannot be executed in any memory area

other than the area starting on its translated origin. The difference between a relocatable program and a non relocatable program is the availability of information concerning the address sensitive instructions in it. A relocatable program can be processed to relocate it to a desired area of memory . A self-relocating program is a program which can perform the relocation of its own address sensitive instructions. It contain the following two section for this purpose : 1 . A table of information concerning the address sensitive instructions. 2.Code to perform the relocation of address sensitive instructions. This is called the relocating logic. The start address of the relocating logic is specified as the execution start address of the program . it uses the load address to perform its own relocation . Execution control is now transferred to the relocated program . A self relocating program can execute in any area of the memory . this is very important in time sharing operating system . ->Self relocating programs are less efficient than relocatable programs. ->There would be no need for linkers if all programs are coded as self relocating programs . ->A self-relocating program needs to find its load address before it can execute its relocating logic.

9) Explain debug monitors.


Dynamic debugging facility is provided by the debug monitor. It includes following activities. 1. 2. 3. 4. 5. Setting breakpoints in the programs Displaying values of variables Accessing new values to variables Initiating a debug conversation when control reaches a breakpoint Testing user defined assertions and predicates.
Page 59

NISHIT KACHIYA

SYSTEM SOFTWARE
When the user a commands to set a breakpoint the debug monitor instruments the program to introduce a sensing instruction before the start of the statement at breakpoint. The debug monitor function can be easily implemented in an interpreter . when a user gives a command to set a breakpoint at statement 150, the debug monitor instruments the program to introduce the instruction. < SI instrn > <code> The debug monitors requires two kind of information regarding the user program. (a)Starting address of program statement in the compiled code. (b)program variables name and address.

10) Write a short note on design of an editor.


The fundamental functions in editing are travelling , editing , viewing and display. Traveling implies movement of the editing context to a new position within the text. This may be done explicitly by the user or may be implies in a user command . Viewing implies formatting the text in a manner desired by the user . A simple text editor may choose to combine the viewing and display functions. this is an abstract view , independent of the physical characteristics of an IO device . The display component maps this view into the physical characteristics of the display device being used. Figure below show the simple editor :

NISHIT KACHIYA

Page 60

SYSTEM SOFTWARE
In editing document, the start of the area to be edited is determined by the current editing pointer maintained by the editing component. The travelling component of the editor actually performs the setting of the current editing and viewing pointers. It also determines the point at which the viewing and editing filters. The current editing pointer can be set or reset explicitly by the user with travelling commands, such as next paragraph and next screen. When a user issue an editing command the editing component invokes the editing filter. Editing component filters the document to generate a new editing buffer based on the current editing pointer as well as on the editing filter parameters. Filtering may simply consists of the selection of contiguous characters beginning at the current point. Current viewing pointer determined the start of the area to be viewed for viewing a document. Current viewing pointer can be set or reset explicitly by the user with a travelling command or implicitly by the user with a travelling command or implicitly by the system as a result of the previous editing operation. For a given position of the editing context, the editing and viewing filters operate on the internal form of text to prepare the forms suitable for editing viewing.

11) Briefly described a loader . what is the importance of it ?


Loader is utility program which takes object code as input prepares it for execution and loads the executable code into the memory . Loader is responsible for initializing the execution process. Importance (Functionality):1. It allocates the space for program in the memory , by calculating the size of the program . 2. It resolves the symbolic references between the object modules by assigning all the user subroutine and library subroutine address. 3. There are some address dependent location in the program . such address constants must be adjusted according to allocated space. 4. It place all the machine instructions and data of corresponding programs and subroutines into the memory .
NISHIT KACHIYA Page 61

SYSTEM SOFTWARE
12) What do you mean by linking ?explain how the linking procedure works with an example ?

NISHIT KACHIYA

Page 62