You are on page 1of 11

PRINCIPLES OF SYSTEM SOFTWARE

NAME - ADITYA ROY KARMAKAR

STUDENT ID - 201001102018

BATCH - BCA1

STREAM - BCA(H)

SEMESTER NO. - 2

ASSIGNMENT NO. -2
1)Explain nested macro call with short example.

ANS:
Nested Macro Call :
MACRO
CAL &P
MOVE , AREGR, &P, ADD, ‘I’ (Set of instruction of macro)
MEND
MACRO X Y Z (Argument X,Y,Z passed through &P1,&P2,&P3)
CAL 1 &P1,P2,P3
CAL &P 1 CAL X
MOVE , AREGR X, ADD X, ‘I’
CAL &P 2 CAL Y
MOVE , AREGR Y, ADD Y, ‘I’
CAL & P3 CAL Z
MOVE , AREGR Z, ADD Z, ‘I’
CAL 1 X,Y,Z
MEND

Example :
A macro may be used in the definition of another macro as illustrated
below.

#define A(x) x*x

#define cost(A,y) A*y

Program illustrates this concept. In this program, Area is a function of x, and


the cost of painting the area is defined as a function of area in the macro
definition.

#include<stdio.h>
#define Area(x) x*x
#define Costpaint(x,y,z) (z*y + Area (x))
void main()
{
int A = 8, B= 6, C = 4;
clrscr();
printf("The area of square= %d\n", Area(A));
printf("Cost of paint= %d\n", Costpaint(A,B,C));
}

2)Write down the advantages and disadvantages of macro


assembler.

ANS: The Advantages Of Macro Assembler:

● It ensures that many functions need not be implemented twice.

● Fewer overhead, many functions are combined and don’t need to be

created an intermediate file.

● Flexibility with the features of combinations of macro and assembler.

The Disadvantages Of Macro Assembler:

The result of the combination of macro processing and pass 1

assembler sometimes suffers from core memory problem of it increases

the complexity of program translation.

3) Write down the advantages and disadvantages of compiler


and go loader.

ANS: Advantages of Compiler and go loaders:

- Simple and easier to implement.

- No additional routines are required to load the compiled code

into the memory.

Disadvantages of Compiler and go loaders:


- Wastage in memory space due to the presence of the assembler.

- There is a need to re-assemble the code every time it is to be run.

- It becomes increasingly difficult to handle large number of segments


when the input code is written in a variety of HLL say one routine in pascal
and one in FORTRAN and so on.

- Such loaders make designing modular programs and systems near


impossible.

4) What is Lex and YACC compiler?

ANS:

LEX

Lex is a computer program that generates lexical analyzers. Mike Lex and
Eric Schmidt are the original developers of Lex. It is a standard lexical
analyzer generator on various UNIX systems. Lex is specified as a part of
the POSIX standard. Generally, Lex is used with the Yacc parser generator.
Furthermore, Lex reads an input stream specifying the lexical analyzer.
Then, it outputs the source code implementing the lexer in the C language.

A Lex file consists of the following three sections:

Definition: Defines macros and imports header files written in C.

Rules: It contains regular expression patterns with C statements. When the


lexer identifies that the text in the input matches a given pattern, it will
execute the associated C code.

Auxiliary Function: This section consists of C statements and functions.

YACC

Yacc stands for Yet Another Compiler-Compiler. Stephan C. Johnson


developed it, and it is used in UNIX systems. It is a standard utility on BSD
and AT&T UNIX. Additionally, GNU based Linux distributions include Bison,
forward-compatible Yacc replacement.

Moreover, the input to Yacc is a grammar of C code that is attached to its


rules. The output is a shift-reduce parser in C. After recognizing the rule, it
executes the C code associated with each rule. Further, the typical actions
include generating the parse tree.

5) Write down the features of scanning and parsing in brief.

ANS:

Scanning: Turning source code into a token stream. This stage removes
white space and comments, and identifies what kind of token each piece
of the code is.

Parsing: Turning a token stream into a parse tree. This stage checks that
the sequence of tokens is grammatically correct and can be grouped
together according to the specifications of how the language works.

6)Differentiate between macro and subroutine with examples.

ANS:

Macro Subroutine

Macro can be called only in the Subroutine can be called from


program it is defined. other programs also.

Macro can have a maximum of 9 Can have any number of


parameters. parameters.

Macro can be called only after its This is not true for Subroutine.
definition.

A macro is defined inside: Subroutine is defined inside:


DEFINE … FORM …..
…. …..
END-OF-DEFINITION. ENDFORM.
Macro is used when the same thing Subroutine is used for
is to be done in a program a modularization.
number of times.

7)Explain with an example of a relocation loader.

ANS:

Relocating Loader: It is used to avoid possible reassembling of all


subroutines. When a simple sub-routine is changed to perform the task of
allocation and linking of the programmers.The general class of reallocating
loader was used. An example of reallocating loader is Binary Symbolic
Subroutine (BSS).The output of a reallocating program is an object
program and information about all other program references.
8)Differentiate between the macro processor and macro
assembler.

ANS:

Macro Assembler Macro Processor

1)It performs Expansion as 1)It only Performs Expansion


well as generate object code

2) Expansion is performed 2)It may have its own pass


during Design Analysis Structure

3)It doesn't require separate 3)It require separate


preprocessor and Assembler preprocessor and Assembler

4)From user point of view it is 4)The user have to run


very simple preprocessor first.

5)Less Time Consuming 5)More time consuming

6)Complex Logic 6)Comparatively easy Logic

7)Data Structure Used : 7)Data Structure used:


All data structures used by MNT, MDT, PNTAB, EVTAB,
Macro processor are SYTAB SSNTAB, KPDTAB,SSTAB
OPTAB , LITAB etc

8)It has three phases : 8)It has two phases :


Macro Definition Processing. Macro Processing and
Macro Expansion and simple Macro Expansion
Assembling
9)Write down the function of LTORG, MNT, PDT.

ANS:

LTORG

The LTORG directive, which stands for 'origin for literals', allows a
programmer to specify where literals should be placed. If a program does
not use an LTORG statement, the assembler would enter all literals used in
the program into a single pool and allocate memory to them when it
encounters the END statement.

MNT(MACRO NAME TABLE)

Each MNT entry consists of :

A) A character string(The macro name)

B)A pointer(Index) to the entry in MDT that corresponds to the beginning of


the macro-definition(MDT Index)
PDT(PORTABLE DATA TERMINAL)

They can also serve as barcode readers, and they are used in large stores,
warehouses, hospitals, or information in the field, to access a database
from a remote location. Others have a touch screen, IrDA, Bluetooth, a
memory card slot, or one or more data capture devices. PDT's frequently
run wireless device management software that allows them to interact
with a database or software application hosted on a server or mainframe
computer.

A Typical PDT

10) Differentiate between one pass and two pass assemblers.

Ans: Difference between one pass and two pass assembler:-

One Pass Assembler Two Pass Assembler

Scans the entire source file only Require two passes to scan the source
once. file.

First pass – responsible for label


definition and introduce them in the
symbol table.
Second pass – translates the
instructions into assembly language or
generates machine code.

Generally Along with pass one , pass two is also


required which
• Deals with syntax.
• Generates actual Opcode.
• Constructs symbol table
• Compute actual address of every
• Creates a label list.
label.
• Identifies the code segment,
• Assign code address for debugging
data segment, stack segment
the information.
etc…
• Translates operand name to
appropriate register or memory code.

• Immediate value is translated to


binary strings (1’s and 0’s).

Cannot resolve forward Can resolve forward references of data


references of data symbols. symbols.

No object program is written, Loader is required as object code is


hence no loader is required generated.

Tends to be faster compared to Two pass assembler requires


two pass. rescanning. Hence slow compared to
one pass assembler.

Only creates tables with all Address of symbols can be calculated.


symbols no address of symbols
is calculated.

You might also like