Sample Solutions Unit Test 1 For Set A, B, C and D
Sample Solutions Unit Test 1 For Set A, B, C and D
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
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
Sol:
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:-
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.
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:
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
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
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
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
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
1 M1 1
2 M2 6
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
10 “ 1 0.0
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
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.
-----------******-----------
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
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:
0 LAB 500
1 LOOP 503
2 VAR 503
Sol: -
3 L1 530
Literal table:
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:
START 500 (AD, 01) (C, 500) (AD, 01) (C, 500)
SUB BREG, ='5' 518 (IS, 03) (RG,02) (L,2) (IS, 03) BREG (L,2)
ORIGIN LAB+3 (IS, 11) (RG,01) (L,4) (IS, 11) AREG (L,4)
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, ®
Macro call: INCR A, B, AREG
2. Keyword parameters: Order can be changed in macro call.
Example:
Prototype statement: INCR &MEM_VAL=, &INC_VAL=, ®=
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).
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
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
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
Start 300
READ A 300) 09 0 ____
LOOP MOVER AREG, A 301) 04 01 ___
END 00 00 001
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
Loop 301
A 305
Literal Table will fill the Address of literal after processing END (sometimes LTORG)
statement.
Literal Table
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
END 00 00 001
1-b Write an algorithm for Pass-II of two-pass assembler and explain with suitable example. 04
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
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
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
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
A pattern is a rule describing the set of lexemes that can represent a particular token in
source program
-----------******-----------
Page 33 of 33