You are on page 1of 8

Pune Institute of Computer Technology, Pune-43

DEPARTMENT OF INFORMATION TECHNOLOGY


(Academic Year – 2019-20 Sem-II)
SAMPLE SOLUTION UNIT TEST - I

Subject: Systems Programming Subject Code: 314451


Class: TE ( IT ) Div: XI [ Max. Marks : 30]
Date: 07/02/2020 Day: Friday Duration: 1 Hour

Instructions to the candidate: SET-C


1. All questions are compulsory. Roll No: -
2. Assume suitable data, if necessary.

Ques. Max
Question
No. Marks
1-a With syntax and example explain types of assembly language statements. 04
Sol: An assembly language statement has the following format:
[Label] <Opcode> <operand specification>
Label:- It is a symbolic name. It is an optional field
Opcode:- Use Assembly mnemonics
operand specification> has following syntax:
<symbolic name> [± <displacement>] [(<index register>)]
• Example:
AGAIN MULT BREG, A
• Three types of assembly statements are:
1. Imperative statement:
An imperative statement indicates an action to be performed during the
execution of the assembled statement.
Each imperative statement converted into one machine instruction.
These are executable statements.
Examples:
MOVER BREG,X
ADD AREG,Y
PRINT RESULT
STOP
2. Declaration statement :
Declaration statements are used for reserving memory for variables.
The syntax of declaration statement is as follow:
[Label] DS <constant>
[Label] DC ‘<value>’
Where DS stands for Declare storage and DC stands for Declare constant.

3. Assembler directive
Assembler directives instruct the assembler to perform certain action
during the assembly program.
Assembler directives are not converted into machine code rather they give
instruction to assembler itself.
Example

Page 1 of 8
Pune Institute of Computer Technology, Pune-43
DEPARTMENT OF INFORMATION TECHNOLOGY
(Academic Year – 2019-20 Sem-II)
SAMPLE SOLUTION UNIT TEST - I

START, END, LTORG, EQU, ORIGIN


1-b What are the assembler Directives? Explain with Example. 04
Sol: - • Assembler directives instruct the assembler to perform certain action during the
assembly program.
• Assembler directives are not converted into machine code rather they give
instruction to assembler itself.
1. START:
Syntax:
START <constant>
This directive instructs the assembler to place first word of the target
program in the memory having the address <constant>.
Example:
START 100
First word of the target program is stored in the memory location 100
onwards.

2. END:
Syntax:
END [<operand specification>]
This directive indicates end of the source program.
The operand specification indicates address of the instruction from where
the execution of program should begin.
Execution control should transfer to label given in operand field.
By default, execution begins with the first instruction of the assembly
program.
3. ORIGIN:
Syntax:
ORIGIN <address specification>
Where <address specification> is an <operand specification> or
<constant>.
This directive indicates that LC should be set to the address given by
<address specification>.
The ORIGIN statement is useful when the target program does not consist
of consecutive memory words.
4. EQU:
Syntax
<symbol> EQU <address specification>
Where <address specification> is either a <constant> or <symbolic name>
± <displacement>.
The EQU statement simply associates the name <symbol> with the
address specified by <address specification>.
However, the address in the location counter is not affected.
5. LTORG:
The LTORG directive, stands for 'origin for literals'.
LTORG allows a programmer to specify where literals should be placed.
Page 2 of 8
Pune Institute of Computer Technology, Pune-43
DEPARTMENT OF INFORMATION TECHNOLOGY
(Academic Year – 2019-20 Sem-II)
SAMPLE SOLUTION UNIT TEST - I

The assembler uses the following scheme for placement of literals:


When the use of a literal is seen in a statement, the assembler enters it into
a literal pool unless a matching literal already exists in the pool.
At every LTORG statement also at the END statement, the assembler
allocates memory to the literals of the literal pool then clears the literal
pool.
1-c Explain Intermediate code generation. 02
 Two Criteria for choice Intermediate Code
Processing Efficiency
Memory Efficiency
 Design or Consider Two variants (alternative) of intermediate code and
comparing them on above criteria
 Intermediate code is sequence of Intermediate code units (IC).
 The Intermediate code consists of a sequence of intermediate code units. (IC
units)
 Each unit consists of the following three fields:
Sol:-  Address
 Representation of mnemonics opcode
 Representation of operands
 There are two variants of intermediate code:
 Variant I
 Variant II
 Address and mnemonics opcode fields are assumed to contain identical
information in both variants.
 But, both variants differ in information contained in operand field

For the given assembly code generate MNT, MDT and expanded code
2-a 07
MACRO START 100
M1 &N, &A1 = ,&R=AREG READ VAR
Sol:- Macro Definition Table (MDT):
MOVEM &R, &N M2 A, OPR =SUB
Index Label, Opcode and Operands (Cards)
SUB &R, &A1 ADD AREG, VAR
1 M1 &N, &A1 = ,&R=AREG
ADD &R, &N LDA CREG, BREG
2 MOVEM BREG, #1
MEND SUB CREG, A
3 SUB BREG, #2
MACRO M1 C, R = BREG, A1 =A
4 ADD BREG, #1
M2 &P, &Q = B, &OPR = A DS 1
5 MEND
DIV VAR DC 2
6 M2 &P, &Q = B, &OPR =
MOVER AREG, &P
MOVER C AREG, #1 DS 3
7
&OPR AREG, &Q
8 #3 AREG, #2
MOVEM BREG, &P
9 MOVEM BREG, #3
MEND
10 MEND

Macro Name Table

Page 3 of 8
Pune Institute of Computer Technology, Pune-43
DEPARTMENT OF INFORMATION TECHNOLOGY
(Academic Year – 2019-20 Sem-II)
SAMPLE SOLUTION UNIT TEST - I

Index Macro Name MDT Index


1 M1 1
2 M2 6

START 100
READ VAR
+ MOVER AREG, A
+ SUB AREG, B
+ MOVEM BREG, A
ADD AREG, VAR
LDA CREG, BREG
SUB CREG, A
+ MOVEM BREG, C
+ SUB BREG, A
+ ADD BREG, C
A DS 1
VAR DC 2
C DS 3
END

2-b What is subroutine linkage? How is it resolved? 03


The way in which a computer makes it possible to call and return from subroutines is
referred to as its subroutine linkage method. The simplest subroutine linkage method is to
save the return address in a specific location, which may be a register dedicated to this
Sol:-
function. Such a register is called the link register. When the subroutine completes its
task, the Return instruction returns to the calling program by branching indirectly through
the link register.
3-a Perform lexical analysis on the given 'C' program 05
main() {
float volume = 0.0, length, breadth, height;
clrscr();
printf("Enter length, breadth and height of cube :\n");
scanf("%f %f %f ", &length, &breadth, &height);
volume = length *breadth* height;
printf("Volume = %f”, volume);
getch();
Page 4 of 8
Pune Institute of Computer Technology, Pune-43
DEPARTMENT OF INFORMATION TECHNOLOGY
(Academic Year – 2019-20 Sem-II)
SAMPLE SOLUTION UNIT TEST - I

}
Sol:-
Terminal Table Identifier Table
Index Symbol Index Symbol Name
1 ( 1 main
2 ) 2 volume
3 { 3 length
4 float 4 breath
5 = 5 height
6 ,
7 ;
8 Literal Table
clrscr
9Index Symbol Name
printf
1
10 “0.0
2
11 Enter length,
scanf
breadth and
12 %
height of cube:
13
3 *%f %f %f
14
4 getch
Volume = %f
15 }
16 &

Uniform Symbol Table


class index token class index token
IDN 1 main TRM 16 &
TRM 1 ( IDN 3 length
TRM 2 ) TRM 6 ,
TRM 3 { TRM 16 &
TRM 4 float IDN 4 breadth
IDN 2 volume TRM 6 ,

Page 5 of 8
Pune Institute of Computer Technology, Pune-43
DEPARTMENT OF INFORMATION TECHNOLOGY
(Academic Year – 2019-20 Sem-II)
SAMPLE SOLUTION UNIT TEST - I

TRM 5 = TRM 16 &


LIT 1 0.0 IDN 5 height
TRM 6 , TRM 2 )
IDN 3 length TRM 7 ;
TRM 6 , IDN 2 volume
IDN 4 breadth TRM 5 =
TRM 6 , IDN 3 length
IDN 5 height TRM 13 *
TRM 7 ; IDN 4 breadth
TRM 8 clrscr TRM 13 *
TRM 1 ( IDN 5 height
TRM 2 ) TRM 7 ;
TRM 7 ; TRM 9 printf
TRM 9 printf TRM 1 (
TRM 1 ( TRM 10 “
TRM 10 “ LIT 4 Volume=%f
LIT 2 Enter length, TRM 6 ,
breath and
height of
cube:\n
TRM 2 ) IDN 2 volume
TRM 7 ; TRM )
TRM 11 scanf TRM ;
TRM 1 ( TRM 14 getch
TRM 10 “ TRM 1 (
LIT 3 %f %f %f TRM 2 )
TRM 10 “ TRM 7 ;
TRM 6 , TRM 15 }

Page 6 of 8
Pune Institute of Computer Technology, Pune-43
DEPARTMENT OF INFORMATION TECHNOLOGY
(Academic Year – 2019-20 Sem-II)
SAMPLE SOLUTION UNIT TEST - I

3-b Explain Input Buffering. 03


• A lexical analyzer may need to read ahead some characters before it can decide on
the token to be returned to the parser. Speed of Lexical Analysis Concern.
• Use Two Pointers (begin_ptr and forward_ptr)
• Input Buffer contain Whole string of input data.
• Used Two Buffer Scheme
• Buffer Pairs
• Sentinels
• Buffer Pairs
• Buffer is divided into two N characters Valve
• N is Number of character eg. 1024 or 4096
• Pointer Lexeme Begin, marks the beginning of the current lexeme.
• Pointer Forward, scans ahead until a pattern match is found.
• Once the next lexeme is determined, forward is set to character at its right
end.
• Lexeme Begin is set to the character immediately after the lexeme just
Sol:-
found.
• If forward pointer is at the end of first buffer half then second is filled with
N input character.
• If forward pointer is at the end of second buffer half then first is filled with
N input character.
• Sentinels
• In buffer pairs we must check, each time we move the forward pointer that
we have not moved off one of the buffers.
• Thus, for each character read, we make two tests.
• We can combine the buffer-end test with the test for the current character.
• We can reduce the two tests to one if we extend each buffer to hold a
sentinel character at the end.
• The sentinel is a special character that cannot be part of the source
program, and a natural choice is the character EOF.

3-c Explain role of Lexical Analyzer. 02


Sol:- • First phase of a compiler
1. Main task
 To read the input characters
 To produce a sequence of tokens used by the parser for syntax analysis
 As an assistant of parser
2.Interaction of lexical analyzer with parser
3. Processes in lexical analyzers
 Scanning
 Pre-processing
• Strip out comments and white space
• Macro functions
 Correlating error messages from compiler with source program
 A line number can be associated with an error message
 Lexical analysis
Page 7 of 8
Pune Institute of Computer Technology, Pune-43
DEPARTMENT OF INFORMATION TECHNOLOGY
(Academic Year – 2019-20 Sem-II)
SAMPLE SOLUTION UNIT TEST - I

4.Terms of the lexical analyzer


 Token
 Types of words in source program
 Keywords, operators, identifiers, constants, etc.
 Lexeme
 Actual words in source program
 Pattern
 A rule describing the set of lexemes that can represent a particular token
in source program
5. Attributes for Tokens
6. Lexical Errors

-----------******-----------

Page 8 of 8

You might also like