0% found this document useful (0 votes)
1K views33 pages

Sample Solutions Unit Test 1 For Set A, B, C and D

The document contains a sample solution to a systems programming unit test question paper. It includes the symbol table, literal table, pool table, and instruction code for an assembly language program. It also explains language processing activities, the working of compile and go loaders, and the macro directives MACRO, MEND, AIF, AGO, LBL, and GBL.

Uploaded by

Pratiksha Kamble
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views33 pages

Sample Solutions Unit Test 1 For Set A, B, C and D

The document contains a sample solution to a systems programming unit test question paper. It includes the symbol table, literal table, pool table, and instruction code for an assembly language program. It also explains language processing activities, the working of compile and go loaders, and the macro directives MACRO, MEND, AIF, AGO, LBL, and GBL.

Uploaded by

Pratiksha Kamble
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

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-D


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

Ques. Max
Question
No. Marks
For the following piece of assembly language code, show the contents of symbol table,
literal table, pool table and IC (Variant I and Variant II). Assume machine opcodes and
size of instruction as 1.
START 100
A DC 10
MOVER AREG, B
MOVEM BREG, = '1'
ADD AREG, = '2'
1-a SUB BREG, = '1' 07
B EQU A + 20
LTORG
STORE AREG, NUM
MOVER CREG, LOOP
ADD BREG, = '1'
NUM DS 5
LOOP DC 10
END

Index Symbol Address


0 A 100
1 B 120
2 NUM 119
3 LOOP 124
Sol:- Literal table :
Symbol Table :

Pool Table :

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

IC (variant I) IC (Variant II)

(AD, 01) (C, 100) (AD, 01) (C, 100)

(DL,02) (C,10) (DL,02) (C,10)

(IS, 04) (RG,01) (S,1) (IS, 04) AREG, B

(IS, 05) (RG,02) (L,0) (IS, 05) BREG, (L,0)

(IS, 01) (RG,01) (L,1) (IS, 01) AREG, (L,1)

(IS, 02) (RG,02) (L,0) (IS, 02) AREG, (L,0)

(AD, 04) (S,0)+20 (AD, 04) (A+20)

(AD, 05) (AD, 05)

(IS,09) (RG,01) (S, 2) (IS,09) AREG. NUM

(IS, 04) (RG,01) (S,3) (IS, 04) CREG LOOP

(IS, 01) (RG,02) (L,2) (IS, 01) BREG (L,2)

(DL, 01) (C,1) (DL, 01) (C,5)

(DL, 02) (C,10) (DL, 02) (C,10)

(AD, 02) (AD, 02)

1-b Write a short note on Language Processing Activities. 03


The fundamental language processing activities divided into two parts.
1. Program generation activities
2. Program execution activities

Sol:

Program generation activities


• A program generation activity aims to generation of a program. Source is the
application domain and target is the PL domain. It bridges specification gap.
• The generator domain is close to the application domain, it is easy for the
designer or programmer to write the specification of the program to be generated.
• A program generator is software that enables an individual to create a program
Page 2 of 33
Pune Institute of Computer Technology, Pune-43
DEPARTMENT OF INFORMATION TECHNOLOGY
(Academic Year – 2019-20 Sem-II)
SAMPLE SOLUTION UNIT TEST - I
with less efforts and prog. Knowledge.
• A user may only be required to specify the step or rules required for the program
and not need to write and code or less code.
Program execution activities
• A program execution activity aims to execute a program written in PL. source is
PL domain and target is execution domain. It bridges execution gap.
• Two popular models for program execution are:
• Program Translation: The program translation model bridges the execution gap
by translating a program written in a PL called source program(SP), into an
equivalent program in the machine language called target program(TP)
• Program Interpretation: It reads the source program and stores it in its memory.
• During interpretation it takes a source statement, determines its meaning, and
performs actions like computation and I/O which implement it.

2-a Explain basic functions of loader. Also explain the working of compile and go loader. 04
A loader is a system program that performs the loading function. It brings object
program into memory and starts its execution. The role of loader is as shown in the
following figure. In figure, translator may be assembler/complier, which generates the
object program and later loaded to the memory by the loader for execution.

Sol:-

compile and go loader.


• In compiler and go loader, the instruction is read line by line, its machine code is
obtained and it is directly put in the main memory at some known address.
• That means the assembler runs in one part of memory and the assembled
machine instructions and data directly put into their assigned memory locations.
• After the completion of loading process, the assembler transfers the control to the
starting instruction of the loaded program.
• This loading scheme is also called as “assemble and go”.
• Example: WATFOR-77, it’s a FORTRAN.
Advantages
• No additional routines are required to load the compiled code into memory.
• Execution speed is generally much superior to interpreted systems.
Page 3 of 33
Pune Institute of Computer Technology, Pune-43
DEPARTMENT OF INFORMATION TECHNOLOGY
(Academic Year – 2019-20 Sem-II)
SAMPLE SOLUTION UNIT TEST - I
• They are simple and easier to implement.
Disadvantages
• There is wastage in memory space due to the presence of the assembler.
• The code must be re-assembled every time it is run.

With format explain the following macro directives: MACRO, MEND, AIF, AGO, LBL
2-b 06
and GBL.
Macro and MEND:
 “A macro is a unit of specification for program generation through expansion.
 Macro definition consist of name, a set of formal parameters and a body of code.
 It replaces macro call into macro definition.
 “The use of macro name with a set of actual parameters (macro call) is replaced
by some code generated from its body (macro definition), this is called macro
expansion.”
 MEND Statement describes end of Macro.

Sol:

AIF:
• Syntax:
AIF (<expression>) <sequencing symbol>
• Where <expression> is a relational expression consists of:
1. Ordinary strings.
2. Formal parameters with their attributes.
3. Expansion time variables.
• If the relational expression evaluates to true, expansion time control is transferred
to the statement containing <sequencing symbol> in its label field.
Page 4 of 33
Pune Institute of Computer Technology, Pune-43
DEPARTMENT OF INFORMATION TECHNOLOGY
(Academic Year – 2019-20 Sem-II)
SAMPLE SOLUTION UNIT TEST - I
• Sequencing symbol(SS) has syntax
.<ordinary string>
• A SS is defined by putting it in the label field of statement in the macro body. It
is used as operand in an AIF, AGO statement for expansion control transfer.

AGO:
• Syntax:
AGO <sequencing symbol>
• It unconditionally transfers expansion time control to the statement containing
<sequencing symbol> in its label field.

LCL and GBL:


• Local expansion time variables can be used only within one macro and it does
not retain its value across the macro call.
• Syantax: LCL <EV specification> [,<EV specification> .. ]
• Global expansion time variables can be used in every macro definition that has a
declaration for it and it retains its value across the macro call.
• Syntax: GBL <EV specification> [,<EV specification> .. ]
• <EV specification> has the syntax &<EV name>, where <EV name> is an
ordinary string.
• Values of EV's can be manipulated through the preprocessor statement SET.
• Syntax: < EV specification > SET <SET-expression>
Example:

Page 5 of 33
Pune Institute of Computer Technology, Pune-43
DEPARTMENT OF INFORMATION TECHNOLOGY
(Academic Year – 2019-20 Sem-II)
SAMPLE SOLUTION UNIT TEST - I
3-a Write a neat diagram explain the phases of compiler. 05

• Lexical Analysis: Lexical Analyzer divides the given source statement into the
tokens.
• Syntax Analysis: The syntax analyzer checks each line of the code and spots
every tiny mistake. If code is error free then syntax analyzer generates the tree.
Sol:

• Semantic analyzer determines the meaning of a source string. It performs


operations like: matching of parenthesis in the expression, Matching of if else
statement, Performing arithmetic operation that are type compatible and
Checking the scope of operation.

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

▪ Intermediate code generator


▪ Two important properties of intermediate code : It should be easy to produce.
And easy to translate into target program. Intermediate form can be represented
using “three address code”. Three address code consist of a sequence of
instruction, each of which has at most three operands.

▪ Code Optimization: It improves the intermediate code.This is necessary to have a


faster execution of code or less consumption of memory.

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

▪ Code Generation: The intermediate code instructions are translated into sequence
of machine instruction.

Using RE to DFA algorithm generate the DFA for the given Regular Expression.
3-b 05
(a+b)*a*b.
Sol:- Syntax Tree For RE:- (a+b)*a*b#

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

Step 2: Calculate Nullable (Red Circle), Firstpos and Lastpos

Step 3: Calculate Followpos


Position follopos
5
4 5
3 3,4
2 1,2,3,4
1 1,2,3,4

Step 4: Design DFA


Initial state = firstpos of root = {1,2,3,4} ----- A
State A:
δ( (1,2,3,4),a) = followpos(1) U followpos(3)
=(1,2,3,4) U (3,4) = {1,2,3,4} ----- A
δ( (1,2,3,4),b) = followpos (2) U followpos (4)
Page 9 of 33
Pune Institute of Computer Technology, Pune-43
DEPARTMENT OF INFORMATION TECHNOLOGY
(Academic Year – 2019-20 Sem-II)
SAMPLE SOLUTION UNIT TEST - I
= (1,2,3,4) U {5}
= {1,2,3,4,5} ----- B
State B:
δ( (1,2,3,4,5),a) = followpos (1) U followpos (3)
= (1,2,3,4) U {3,4}
= {1,2,3,4} ----- A
δ( (1,2,3,4,5),b) = followpos (2) U followpos (4)
= (1,2,3,4) U {5}
= {1,2,3,4,5} ----- B
Transition Table:-

State a b
A={1,2,3,4} A B
B={1,2,3,4,5} A B
DFA:

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

Page 10 of 33
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
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
Sol: 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
START, END, LTORG, EQU, ORIGIN
Page 11 of 33
Pune Institute of Computer Technology, Pune-43
DEPARTMENT OF INFORMATION TECHNOLOGY
(Academic Year – 2019-20 Sem-II)
SAMPLE SOLUTION UNIT TEST - I
1-b What are the assembler Directives? Explain with Example. 04
• 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
Sol: -
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.
The assembler uses the following scheme for placement of literals:
Page 12 of 33
Pune Institute of Computer Technology, Pune-43
DEPARTMENT OF INFORMATION TECHNOLOGY
(Academic Year – 2019-20 Sem-II)
SAMPLE SOLUTION UNIT TEST - I
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

MACRO START 100


M1 &N, &A1 = ,&R=AREG READ VAR
MOVEM &R, &N M2 A, OPR =SUB
SUB &R, &A1 ADD AREG, VAR
ADD &R, &N LDA CREG, BREG
MEND SUB CREG, A
2-a 07
MACRO M1 C, R = BREG, A1 =A
M2 &P, &Q = B, &OPR = A DS 1
DIV VAR DC 2
MOVER AREG, &P C DS 3
&OPR AREG, &Q
MOVEM BREG, &P
MEND

Page 13 of 33
Pune Institute of Computer Technology, Pune-43
DEPARTMENT OF INFORMATION TECHNOLOGY
(Academic Year – 2019-20 Sem-II)
SAMPLE SOLUTION UNIT TEST - I
Macro Definition Table (MDT):
Index Label, Opcode and Operands (Cards)
1 M1 &N, &A1 = ,&R=AREG
2 MOVEM BREG, #1
3 SUB BREG, #2
4 ADD BREG, #1
5 MEND
6 M2 &P, &Q = B, &OPR =
7 MOVER AREG, #1
8 #3 AREG, #2
9 MOVEM BREG, #3
10 MEND

Macro Name Table

Index Macro Name MDT Index

1 M1 1

2 M2 6

Sol:- 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

Page 14 of 33
Pune Institute of Computer Technology, Pune-43
DEPARTMENT OF INFORMATION TECHNOLOGY
(Academic Year – 2019-20 Sem-II)
SAMPLE SOLUTION UNIT TEST - I
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.
Perform lexical analysis on the given 'C' program
main() {
float volume = 0.0, length, breadth, height;
clrscr();
printf("Enter length, breadth and height of cube :\n");
3-a 05
scanf("%f %f %f ", &length, &breadth, &height);
volume = length *breadth* height;
printf("Volume = %f”, volume);
getch();
}

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

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 clrscr Literal Table

9 printf Index Symbol Name

10 “ 1 0.0

11 scanf 2 Enter length,


breadth and
Sol:- 12 % height of
cube:
13 *
3 %f %f %f
14 getch
4 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 16 of 33
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 17 of 33
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
Sol:-
just 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


• 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
Sol:- ➢ As an assistant of parser
2.Interaction of lexical analyzer with parser
3. Processes in lexical analyzers
▪ Scanning
➢ Pre-processing
Page 18 of 33
Pune Institute of Computer Technology, Pune-43
DEPARTMENT OF INFORMATION TECHNOLOGY
(Academic Year – 2019-20 Sem-II)
SAMPLE SOLUTION UNIT TEST - I
• 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
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 19 of 33
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-B


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

Ques. Max
Question
No. Marks
Generate (Pass I) symbol table, literal table, pool table and Intermediate code (Variant I
and II) with Machine Code (Output of Pass II) for the given assembler program. Assume
a hypothetical instruction set with every instruction of length 1 byte.
START 500
LAB DS 15
MOVEM AREG, VAR
ADD AREG, LAB
MOVER BREG, ='10'
SUB BREG, ='5'
MULT BREG, ='10'
1-a PRINT VAR 08
LTORG
ORIGIN LAB+3
LOOP MOVER CREG, ='5'
LOAD AREG, ='2'
VAR EQU LOOP
ORIGIN VAR + 25
ADD CREG, L1
STOP
L1 DC '12'
END
Symbol Table:

Index Symbol Address

0 LAB 500

1 LOOP 503

2 VAR 503
Sol: -
3 L1 530

Literal table:

Index Symbol Address

0 =‘10’ 521

1 =‘5’ 522

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

2 =’5’ 531

3 =’2’ 532

Pool Table:

Literal No

Intermediate Code:

LC IC (variant I) IC (Variant II)

START 500 (AD, 01) (C, 500) (AD, 01) (C, 500)

(DL, 02) (C,15) (DL, 02) (C,15)


LAB DS 15 500
(IS, 05) (RG,01) (S,2) (IS, 05) AREG, VAR
MOVEM AREG, VAR 515
(IS, 01) (RG,01) (S,0) (IS, 01) AREG, LAB
ADD AREG, LAB 516 (IS, 04) (RG,02) (L,0) (IS, 04) BREG (L,0)
MOVER BREG, ='10' 517 (IS, 02) (RG,02) (L,1) (IS, 02) BREG (L,1)

SUB BREG, ='5' 518 (IS, 03) (RG,02) (L,2) (IS, 03) BREG (L,2)

(IS, 10) (S,2) (IS, 10) VAR


MULT BREG, ='10' 519
(AD,05) (AD,05)
PRINT VAR 520
(AD,03) (C, 503) (AD,03) (C, 503)
LTORG 521, 522 (IS, 04) (RG,03) (L,3) (IS, 04) CREG (L,3)

ORIGIN LAB+3 (IS, 11) (RG,01) (L,4) (IS, 11) AREG (L,4)

LOOP MOVER CREG, ='5' 503 (AD,04) (S, 1) (AD,04) LOOP

(AD,03) (C, 528) (IS,00)


LOAD AREG, ='2' 504
(IS, 01) (RG,03) (S,3) (IS, 01) CREG L1
VAR EQU LOOP
(IS, 00) (IS, 00)
ORIGIN VAR + 25 (DL,01) (C,12) (DL,01) (C,12)

ADD CREG, L1 528 (AD, 02) (AD, 02)

STOP 529

L1 DC '12' 530

END 531,532

Page 21 of 33
Pune Institute of Computer Technology, Pune-43
DEPARTMENT OF INFORMATION TECHNOLOGY
(Academic Year – 2019-20 Sem-II)
SAMPLE SOLUTION UNIT TEST - I
1-b Explain Listing and error reporting in assembler with example. 02
− An assembly program may contain errors.

− Error specification at proper place affects the effectiveness of reporting and speed as
well as memory requirements of the assembler.
− Detection of Errors has always been important task for language processor. It is
impossible to correct errors in source by simply looking at target code even if it is
reported that there is an error.
− One probable solution is to report errors after pass 1 rather than pass 2, but errors like
references to undefined variables only can be found at 2nd pass only.
− These factors make error reporting a complicated procedure.
− It is inevitable to report errors only after pass 2 and to overcome the former issue
Sol: - compilers print both target code and error description against the source itself. This
makes debugging easier.
− It may be necessary to report these errors effectively.
− Some errors can be reported at the end of the source program.
− Some of the typical errors include:
o Syntax errors like missing commas.
o Invalid opcode.
o Duplicate definition of a symbol.
o Undefined Symbol.
o Missing START statement.
Explain following Macro facilities with example.
2-a i) Expansion time Variable 05
ii) Change of flow during Macro expansion
Expansion time Variable: -
• Expansion time variables (EV's) are variables which can only be used during the
expansion of macro calls.
• Types of expansion time variables:
1. Local expansion time variables
Example: LCL &A
local variable A is created.
Sol: - 2. Global expansion time variables
Example: GBL &A
Global variable A is created.
• Local expansion time variables can be used only within one macro and it does not
retain its value across the macro call.
• Syantax: LCL <EV specification> [,<EV specification> .. ]
• Global expansion time variables can be used in every macro definition that has a
declaration for it and it retains its value across the macro call.
Page 22 of 33
Pune Institute of Computer Technology, Pune-43
DEPARTMENT OF INFORMATION TECHNOLOGY
(Academic Year – 2019-20 Sem-II)
SAMPLE SOLUTION UNIT TEST - I
• Syntax: GBL <EV specification> [,<EV specification> .. ]
• <EV specification> has the syntax &<EV name>, where <EV name> is an
ordinary string.
• Values of EV's can be manipulated through the preprocessor statement SET.
• Syntax: < EV specification > SET <SET-expression>
• Example:
Expansion time loops: -
• It is often necessary to generate many similar statements during the expansion of
a macro.
• This can be achieved by writing similar model statements in the macro.
• Expansion time loops can be written using expansion time variables (EV’s) and
expansion time control transfer statements AIF and AGO.
• REPT Statement
• Syntax:
REPT <expression>
• Example: Declare 10 constants with the values 1, 2, …., 10 using REPT
statement.
• IRP
• Syntax
IRP <formal parameter>, <argument list>
• The formal parameter mentioned in the statement takes successive values from
the argument list.
• For each value the statements between the IRP and ENDM statements are
expanded once.
• A macro call CONSTS 4, 10 leads to declaration of 3 constants with the values 4,
7, and 10.
• Example:
2-b Explain different parameter passing mechanisms in macro processor with example. 05
Types of Parameters: -
• Positional parameters
• Keyword parameters
• Default specification of parameter
• Macro with mixed parameter lists
• Other uses of parameters
Mainly Two types of formal parameters are:
1. Positional parameters: Order cannot be changed in macro call.
Sol:- Example:
Prototype statement: INCR &MEM_VAL, &INC_VAL, &REG
Macro call: INCR A, B, AREG
2. Keyword parameters: Order can be changed in macro call.
Example:
Prototype statement: INCR &MEM_VAL=, &INC_VAL=, &REG=
Macro call: INCR INCR_VAL=B, REG=AREG, MEM_VAL=A
Note: Explain Briefly with Example

Page 23 of 33
Pune Institute of Computer Technology, Pune-43
DEPARTMENT OF INFORMATION TECHNOLOGY
(Academic Year – 2019-20 Sem-II)
SAMPLE SOLUTION UNIT TEST - I
Explain the processing of given statement w. r. t first three phases of compiler.
3-a 05
R=(b*b-4*a*c)/(2*a).

R = (b*b-4*a*c)/(2*a)

Sol: -

Note: - Here, n1, n2, n3 and n4 is Id1, Id2, Id3 and Id4 respectively (all are identifiers).

Convert the following RE to DFA


3-b 05
(1+ )*01
▪ Syntax Tree For R/E= (a+ε)*ab
▪ Syntax Tree for Augmented RE= (a+ε)*ab#
▪ For ε-Leaf node not assigning any number
▪ Step 1: Construct Syntax Tree
▪ Step 2: Nullable node (Here, * is only nullable node represented by red circle)

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

▪ Step 3: Calculate firstpos and lastpos

▪ Step 4: Calculate followpos

Position followpos
1 1,2
2 3
3 4
▪ Step 5: Construct DFA
▪ Initial state = Firstpos of root = {1,2} ----- A
▪ State A: δ( (1,2),a) = followpos(1) U followpos(2)
▪ =(1,2) U (3) = {1,2,3} ----- B
▪ δ( (1,2),b) = ɸ
▪ State B: δ( (1,2,3),a) = followpos(1) U followpos(2)
Page 25 of 33
Pune Institute of Computer Technology, Pune-43
DEPARTMENT OF INFORMATION TECHNOLOGY
(Academic Year – 2019-20 Sem-II)
SAMPLE SOLUTION UNIT TEST - I
▪ =(1,2) U (3) = {1,2,3} ----- B

▪ δ( (1,2,3),b) = followpos (3)
▪ ={4} ----- C

Transition Table:-

State a b
A={1,2} B ɸ
B={1,2,3} B C
C={4} ɸ ɸ
DFA:

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

Page 26 of 33
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-A


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

Ques. Max
Question
No. Marks
Explain how a single pass assembler works for the following example:
START 300
READ A
LOOP MOVER AREG, A
1-a SUB AREG, =’1’ 06
BC GT, LOOP
STOP
A DS 1
END

Assembly Statements Memory Opcode Register Memory


Location Operand Operand

Start 300
READ A 300) 09 0 ____
LOOP MOVER AREG, A 301) 04 01 ___

SUB. AREG, =’1’ 302) 02 01 ___


.BC GT, LOOP 303) 07 04 301
STOP 304) 00 0 000
Sol: -
A DS 1 305) No code generation for DS

END 00 00 001

Table of Incomplete Instructions (TII)

Instruction Address (LC No) Symbol

300 A

302 =’1’

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

Symbol Table

Symbol Name Address

Loop 301

A 305
Literal Table will fill the Address of literal after processing END (sometimes LTORG)
statement.
Literal Table

Index Symbol Address

0 =‘1’ 306

Pool Table

Literal No

After Resolving Forward Reference and END Statement for literal address.
Assembly Statements Memory Opcode Register Memory
Location Operand Operand
Start 300
READ A 300) 09 0 305
LOOP MOVER AREG, A 301) 04 01 305

SUB. AREG, =’1’ 302) 02 01 306


.BC GT, LOOP 303) 07 04 301
STOP 304) 00 0 000
A DS 1 305) No code generation for DS

END 00 00 001
1-b Write an algorithm for Pass-II of two-pass assembler and explain with suitable example. 04

• loc_cntr : Location Counter


• littab_ptr : Points to an entry in LITTAB
• pooltab_ptr : Points to an entry in POOLTAB
• machine_code_buffer : Area for constructing code for one statement
• code_area : Area for assembling the target program
Sol: - • code_area_address : Contains address of code_area
1. Code_area_adress= address of code_areas;
Pooltab_ptr=1;
Loc_cntr=0;
2. While next statement is not an END statement
a) Clear machine_code_buffer;
b) if an LTORG statement
Page 28 of 33
Pune Institute of Computer Technology, Pune-43
DEPARTMENT OF INFORMATION TECHNOLOGY
(Academic Year – 2019-20 Sem-II)
SAMPLE SOLUTION UNIT TEST - I
i) Process literals in LITTAB and assemble the literals in
machine_code_buffer.
ii) size= size of memory area required for literals
iii) pooltab_ptr=pooltab_ptr +1;
c) If a START or ORIGIN statement
I. loc_cntr=value specified in operand field;
II. size=0;
d) If a declaration statement
I. If a DC statement then assemble the constant in
machine_code_buffer;
II. size= size of memory area required by DC/DS;
e) If an imperative statement
I. Get operand address from SYMTAB or LITTAB
II. Assemble instruction in machine_code_buffer;
III. size=size of instruction;
f) If size≠ 0 then
I. Move contents of machine_code_buffer to the address
code_area_address+loc_cntr;
II. loc_cntr=loc_cntr+size;
3. Processing END statement
a) Perform steps 2(b) and 2(f).
b) Write code_area into output file
For the following assembly language program show MNT, MDT, stack organization and the
expanded code for the given assembly language program.

MACRO START
XYZ &A MIT HELLO
MOVER AREG,&A ADD AREG, BREG
MEND
2-a HELLO YALE
MACRO 10
MIT &Z
YALE EQUS
MACRO ALL DC 3
&Z &W END
ADD BREG, &W
XYZ ALL
MEND
MOVER &Z, ALL
MEND

Page 29 of 33
Pune Institute of Computer Technology, Pune-43
DEPARTMENT OF INFORMATION TECHNOLOGY
(Academic Year – 2019-20 Sem-II)
SAMPLE SOLUTION UNIT TEST - I
Macro Definition Table (MDT):
Index Label, Opcode and Operands (Cards)
1 XYZ &A
2 MOVER AREG, #1
3 MEND
4 MIT &Z
5 MACRO
6 #1, &W
7 ADD BREG, &W
8 XYZ ALL
9 MEND
10 MOVER #1, ALL
11 MEND
12 HELLO &W
13 ADD BREG, #1
Sol: - 14 XYZ ALL
15 MEND

Macro Name Table

Index Macro Name MDT Index

1 XYZ 1

2 MIT 4

3 HELLO 12
START
+ MOVER HELLO, ALL
ADD AREG, BREG
+ ADD BREG, YALE
+ MOVER AREG, ALL
YALE EQUS
ALL DC 3
END
For the given 'C' code, generate the output of lexical analysis.
//My first C Program
void main ( ) {
int i, j; clrscr( );
3-a scanf("%d %d",&i,&j); 06
while (i <= j)
{ i++; j--; }
printf("C Programming!");
getch( ); }

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

Terminal Table Identifier Table


Index Symbol Index Symbol Name
1 void 1 main
2 ( 2 i
3 ) 3 j
4 {
5 float
6 =
Literal Table
7 ,
Index Symbol Name
8 ;
1 %d%d
9 clrscr
2 C Programming!
10 printf
11 “
Sol: - 12 scanf
13 %
14 *
15 getch
16 }
17 while
18 ++
19 <=
20 &
21 --

Uniform Symbol Table


class index token class index token
TRM 1 void TRM 2 (

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

IDN 1 main IDN 2 i


TRM 2 ( TRM 19 <=
TRM 3 ) IDN 3 j
TRM 4 { TRM 3 )
TRM 5 int TRM 4 {
IDN 2 i IDN 2 i
TRM 6 , TRM 18 ++
IDN 3 j TRM 8 ;
TRM 8 ; IDN 3 j
TRM 9 clrscr TRM 21 --
TRM 2 ( TRM 8 ;
TRM 3 ) TRM 16 }
TRM 8 ; TRM 10 printf
TRM 12 scanf TRM 2 (
TRM 2 ( TRM “
TRM 11 “ LIT 2 C
programming!
LIT 1 %d%d TRM 11 “
TRM 11 “ TRM 3 )
TRM 6 , TRM 8 ;
TRM 20 & TRM 15 getch
IDN 2 i TRM 2 (
TRM 6 , TRM 3 )
TRM 20 & TRM 8 ;
IDN 3 j TRM 16 }
TRM 3 )
TRM 8 ;
TRM 17 while

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

3-b Define the term Lexeme, Token and Pattern with Example. 04
Token: Token is a sequence of characters that can be treated as a single logical entity.
Typical tokens are,
1) Identifiers 2) keywords 3) operators 4) special symbols 5)constants
Pattern: A set of strings in the input for which the same token is produced as output. This
set of strings is described by a rule called a pattern associated with the token.
Lexeme: A lexeme is a sequence of characters in the source program that is matched by
the pattern for a token.
Example:
Description of token

Token lexeme pattern

const const const


Sol: -
if if if
< or <= or = or < > or >= or letter
relation <,<=,= ,< >,>=,> followed by letters & digit

i pi any numeric constant

nun 3.14 All combinations of digits


Starts with letter and followed by
Identifier core all combinations of letter and digit

A pattern is a rule describing the set of lexemes that can represent a particular token in
source program

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

Page 33 of 33

You might also like