Total No. of Questions : 4] SEAT No.
8
23
P8557 [Total No. of Pages : 1
ic-
Oct-22/TE/Insem - 527
tat
8s
T.E. (Computer Engineering)
2:0
SYSTEMS PROGRAMMING AND OPERATING SYSTEM
02 91
(2019 Pattern) (Semester - I) (310243)
0:4
0
21
Time : 1 Hour]
6/1 13 [Max. Marks : 30
0
Instructions to the candidates:
0/2
.23 GP
1) Neat diagrams must be drawn wherever necessary.
2) Figures to the right indicate full marks.
E
80
3) Assume suitable data, if necessary.
8
C
23
ic-
Q1) a) Draw and explain flowchart of Pass-I of two pass assembler with suitable
16
tat
example. [8]
8.2
8s
b) Differentiate between literal and immediate operand. [7]
.24
2:0
91
49
0:4
OR
30
21
Q2) a) Explain in detail with a suitable example, the formates and contents of
01
02
databases used in assembler design. [8]
0/2
GP
b) Explain algorithm of pass 1 of two pass assembler. [7]
6/1
CE
80
8
23
Q3) a) Define Macro. What are the advantages of macro facility? How they are
.23
different from functions? [8]
ic-
16
tat
8.2
8s
b) Write Short note on [7]
.24
2:0
i) Compiler
91
49
0:4
ii) Interpreter
30
21
OR
01
02
0/2
Q4) a) What are different data structures required for Two Pass Macro
GP
Processor? Justify which data structures are implemented at that time of
6/1
CE
processing Macro definition, Macro call and Macro Expansion. [8]
80
.23
b) Explain argument passing mechanism in Macros with suitable examples?
[7]
16
8.2
.24
49
T.E. (Computer Engineering)
SYSTEMS PROGRAMMING AND OPERATING SYSTEM
INSEM IMPORTANT INSEM QUESTION ANSWERS
Q.1] Draw and explain flowchart of Pass-I of two pass assembler with suitable example.
ANS: Pass-I of a Two-Pass Assembler:
The Pass-I of a two-pass assembler is responsible for scanning the source code and
building a symbol table. The symbol table keeps track of labels and their corresponding
memory addresses.
Here's a simple explanation of the flowchart:
1. Start: The assembler starts by reading the first line of the source code.
2. Check for Label: It checks whether the current line has a label. Labels are often
followed by a colon (e.g., LOOP:). If a label is found, the assembler adds it to the
symbol table along with the memory address where it appears.
3. Process Opcode and Operands: The assembler then processes the opcode
(instruction mnemonic) and its operands (parameters). It calculates the memory
required for the instruction and updates the location counter accordingly.
4. Update Symbol Table: If there are any labels used as operands, the assembler
checks if they already exist in the symbol table. If not, it adds them along with the
current value of the location counter.
5. Move to Next Line: After processing the current line, the assembler moves to the
next line of the source code and repeats the process.
6. Repeat Steps 2-5: The assembler continues this process until it has scanned the
entire source code.
7. End of Pass-I: Once the entire source code is scanned, the assembler has built the
symbol table, containing all the labels and their corresponding memory addresses.
Example:
Let's consider a simple assembly language program:
START LDA A
ADD B
STA RESULT
HLT
A DAT 5
B DAT 7
RESULT DAT 0
In this example, here's how Pass-I would work:
1. Start: The assembler starts with the first line (START LDA A).
2. Check for Label: It finds a label START and adds it to the symbol table with the
current location counter value.
3. Process Opcode and Operands: It processes the opcode LDA and its operand A,
updates the location counter.
4. Update Symbol Table: Since A is used as an operand, it's added to the symbol table
if not already present.
5. Move to Next Line: The assembler moves to the next line (ADD B) and repeats the
process.
6. Repeat Steps 2-5: The assembler continues this process for each line of the source
code.
7. End of Pass-I: The assembler has built the symbol table with entries for START, A,
B, and RESULT.
Q.2] Differentiate between literal and immediate operand.
ANS:
Literal Operand:
1. Definition: A literal operand is a constant value directly specified within the
instruction itself. It is used to provide fixed data values directly to an instruction.
2. Usage: Literals are typically used when you want to use a constant value as an
operand for an instruction.
3. Example: If you have an instruction like ADD R1, #10, the #10 is a literal operand,
representing the value 10.
4. Variability: Literal operands remain constant throughout the execution of the
program. They do not change unless you manually modify the instruction.
5. Storage: Literal values are often stored in memory at a specific location associated
with the instruction. This memory location is usually determined during assembly
and may be different for different instances of the same literal value.
Immediate Operand:
1. Definition: An immediate operand is a value that is directly used by an instruction
without needing to fetch it from memory. It is often used for quick, simple
operations.
2. Usage: Immediate operands are used when you want to perform an operation using
a constant value immediately without fetching it from memory.
3. Example: In an instruction like ADD R2, R3, #5, the #5 is an immediate operand,
representing the value 5 that will be directly used in the addition.
4. Variability: Immediate operands are constant values that are directly embedded
within the instruction. They do not change during program execution.
5. Calculation: The value of an immediate operand is used directly in the arithmetic or
logical operation specified by the instruction.
6. Efficiency: Immediate operands can make certain operations faster since the value
is immediately available to the processor without requiring memory access.
Q.3] Explain in detail with a suitable example, the formates and contents of
databases used in assembler design.
ANS:
1. Opcode Database:
Format: This database contains a list of operation codes (opcodes) associated with
assembly language instructions. Each entry includes the mnemonic of the
instruction and its corresponding binary opcode representation.
Contents: It stores the mapping between assembly instructions and their binary
machine code equivalents.
Example: Let's consider an example opcode database entry:
Mnemonic: ADD
Binary Opcode: 0001
2. Addressing Mode Database:
Format: This database lists the various addressing modes supported by the
assembler, along with their binary representations. Addressing modes determine
how operands are specified in instructions (e.g., direct addressing, immediate
addressing).
Contents: It contains a collection of addressing modes, each with its
corresponding binary encoding.
Example: An addressing mode entry:
Addressing Mode: Direct Addressing
Binary Representation: 01
3. Symbol Table:
Format: The symbol table is a data structure that holds information about symbols
(labels and variable names) used in the assembly code. It stores the symbol name
along with its corresponding memory address.
Contents: It includes entries for labels and variable names, with associated
memory addresses or values.
Example: A symbol table entry:
Symbol: LOOP
Memory Address: 200
4. Literal Table:
Format: The literal table stores constant values used in the assembly code. It
records the literal value and its associated memory address.
Contents: It contains entries for each constant value used in the code.
Example: A literal table entry:
Literal Value: 42
Memory Address: 300
5. Instruction Format Database:
Format: This database outlines the format of different assembly language
instructions, including the positions of opcodes, registers, and addressing mode
bits.
Contents: It provides a detailed breakdown of how instructions are structured in
terms of their different components.
Example: Instruction format for a basic arithmetic instruction:
Opcode: 4 bits
Source Register: 3 bits
Destination Register: 3 bits
Addressing Mode: 2 bits
6. Error Code Database:
Format: This database contains a list of error codes and their corresponding error
messages that the assembler can generate when it encounters issues during
assembly.
Contents: It provides meaningful error messages for various possible errors.
Example: An error code and message:
Error Code: 1001
Error Message: "Undefined label encountered: 'MISSING_LABEL'"
Q.4] Explain algorithm of pass 1 of two pass assembler.
ANS:
Algorithm for Pass 1 of Two-Pass Assembler:
1. Initialize Data Structures:
Initialize the Location Counter (LC) to the starting memory location.
Initialize the Symbol Table and Literal Table data structures.
2. Start Reading Source Code:
Read the first line of the source code.
3. Check for Label:
Check if the current line has a label (ends with a colon). If yes, extract the
label name.
Add the label name to the Symbol Table along with the current LC value.
If the label is a duplicate entry, generate an error.
4. Process Opcode and Operands:
Extract the opcode and operands (if any) from the current line.
Determine the length (in bytes) required for the instruction based on the
opcode and addressing mode.
5. Check for Constants (Literals):
Scan the operands to identify constants (literals) designated by special
characters (like '#' or '=').
If a literal is found, add it to the Literal Table with a temporary address.
6. Update Location Counter (LC):
Increment the LC by the length of the current instruction.
7. Repeat Steps 2-6:
Continue reading and processing each line of the source code until the end of
the program.
8. Resolve Literal Addresses:
After processing the entire source code, assign actual memory addresses to
literals in the Literal Table, starting from a suitable address beyond the
program code.
9. End of Pass 1:
Pass 1 is completed. The Symbol Table and Literal Table are populated with
necessary information.
Q.5] Define Macro. What are the advantages of macro facility? How they are different
from functions ?
ANS: Macro:
A macro in programming is a way to define a sequence of instructions or code snippets
that can be reused multiple times in a program. It allows you to define your own custom
instructions, making your code more readable, modular, and efficient.
Advantages of Macro Facility:
The macro facility offers several advantages:
1. Code Reusability: Macros allow you to define a set of instructions once and use
them multiple times in your program. This reduces code duplication and makes the
code easier to maintain.
2. Modularity: By encapsulating a sequence of instructions within a macro, you can
create modular code that can be easily managed and modified.
3. Readability: Macros enable you to give meaningful names to code snippets, making
the code more human-readable and understandable.
4. Efficiency: Macros can result in more efficient code by optimizing repetitive or
complex sequences of instructions. This can lead to smaller executable programs.
5. Customization: You can customize macros for specific tasks, adapting them to
different situations by changing the parameters passed to them.
6. Abstraction: Macros abstract complex operations into simpler function-like calls,
improving the clarity of the main program logic.
Difference Between Macros and Functions:
In simple terms, macros and functions are both tools for code reuse, but they work
differently:
1. Expansion: Macros are expanded directly in the source code during preprocessing.
The macro code is inserted wherever it's called. Functions, on the other hand, are
compiled separately and called during runtime.
2. Overhead: Macro expansion can potentially generate redundant code in multiple
places, leading to increased code size. Functions have a single instance of code,
reducing redundancy.
3. Performance: Macros can sometimes lead to more efficient code due to inline
expansion. Functions involve function call overhead, which might affect
performance slightly.
4. Arguments: Macros can take arguments just like functions, but their arguments are
directly replaced in the expanded code. Function arguments are evaluated at
runtime.
5. Debugging: Macros can be challenging to debug since errors might appear at the
point of expansion rather than where the macro is defined. Functions have well-
defined boundaries, making debugging easier.
Q.6] Write Short note on i) Compiler ii) Interpreter
ANS: Compiler:
A compiler is a software tool that translates high-level programming code written in
languages like C, C++, Java, etc., into machine code or intermediate code that a
computer's hardware can understand and execute. The compilation process involves
several stages, including lexical analysis (breaking code into tokens), syntax analysis
(building a parse tree), semantic analysis (checking for correct semantics), code
optimization, and code generation.
Key points about compilers:
Translation: Compilers convert entire programs into machine-readable code before
execution.
Intermediate Code: Some compilers generate intermediate code that's executed by
an interpreter or translated further to machine code.
Performance: Compiled programs often run faster because they're translated in
advance, optimizing the code.
Executable Output: Compilers produce standalone executable files that can be run
directly on the target machine.
Examples: GCC (GNU Compiler Collection) for C/C++, Java's javac, and Microsoft
Visual C++ compiler.
Interpreter:
An interpreter is a software tool that directly executes high-level code line by line. It
reads source code, interprets it, and performs the required actions without the need for
creating a separate compiled output. Interpreted languages include Python, JavaScript,
Ruby, etc.
Key points about interpreters:
Execution: Interpreters read, analyze, and execute code line by line in real-time.
No Separate Compilation: Unlike compilers, interpreters don't generate standalone
executables. They directly execute the source code.
Flexibility: Interpreted languages often offer more dynamic features due to their
real-time execution.
Ease of Debugging: Errors can be easier to track down as they are often reported
as they occur.
Examples: Python interpreter, Node.js for JavaScript, and Ruby interpreter.
Q.7] What are different data structures required for Two Pass Macro Processor? Justify
which data structures are implemented at that time of processing Macro definition,
Macro call and Macro Expansion.
ANS: In a Two-Pass Macro Processor, which is used to handle macros in assembly
language programs, different data structures are required to effectively process macro
definitions, macro calls, and macro expansions. Here's a breakdown of the required data
structures for each phase and why they are used:
1. Data Structures for Macro Definition:
During the first pass of the two-pass macro processor, when macros are defined, the
following data structures are typically used:
Macro Definition Table (MDT): This table stores the actual macro definitions. Each
entry in the MDT corresponds to a macro and contains the macro name, formal
parameters, and the sequence of instructions that make up the macro body.
Macro Name Table (MNT): The MNT keeps track of the names of macros defined in
the source code. Each entry in the MNT provides information about the macro,
such as its name, location in the MDT, and the number of formal parameters.
2. Data Structures for Macro Call:
During the first pass, when macros are called in the source code, the following data
structure is used:
Macro Invocation Table (MIT): The MIT records the details of macro invocations in
the source code. It stores information like the macro name, actual parameters
provided in the call, and the location of the macro call.
3. Data Structures for Macro Expansion:
During the second pass, when macros are expanded, the following data structures are
used:
Actual Argument Table (AAT): The AAT holds the values of actual arguments
provided in a macro call. Each entry corresponds to an actual argument and is
associated with a formal parameter's position.
Parameter Replacement Table (PRT): The PRT keeps track of which formal
parameters are replaced with corresponding actual arguments during macro
expansion. It helps in replacing formal parameters with actual arguments in the
macro body.
Justification for Data Structures:
Macro Definition: During macro definition, the MDT stores the actual macro code,
allowing the processor to understand the macro's functionality. The MNT keeps
track of macro names for easy reference and retrieval.
Macro Call: The MIT records macro calls' details for future reference during macro
expansion. It helps in tracking where macros were invoked and what arguments
were provided.
Macro Expansion: The AAT is crucial to hold actual arguments for proper
parameter replacement during macro expansion. The PRT ensures that the right
formal parameters are replaced by their respective actual arguments.
Q.8] Explain argument passing mechanism in Macros with suitable examples?
ANS: Argument passing mechanisms in macros are used to pass values from the calling
code (where the macro is used) to the macro body for processing. There are two common
argument passing mechanisms: positional and keyword arguments. Let's explain both
with simple examples:
1. Positional Argument Passing:
In positional argument passing, the values are passed in a specific order corresponding
to the formal parameters defined in the macro. The values are matched based on their
positions.
Example: Consider a macro called SUM that calculates the sum of two numbers. It takes
two parameters, A and B.
MACRO SUM A, B
LDA A
ADD B
STA RESULT
MEND
START
SUM X, Y
HLT
X DAT 5
Y DAT 10
RESULT DAT 0
Here, X and Y are the actual arguments passed to the SUM macro. They are matched
with A and B respectively based on their positions.
2. Keyword Argument Passing:
Keyword argument passing allows you to pass values to a macro based on the names of
the formal parameters. This way, the order of arguments doesn't matter.
Example: Consider a macro called SWAP that swaps the values of two variables. It takes
two parameters, VAR1 and VAR2.
MACRO SWAP VAR1=&A, VAR2=&B
MOV TEMP, VAR1
MOV VAR1, VAR2
MOV VAR2, TEMP
MEND
START
SWAP VAR1=X, VAR2=Y
HLT
X DAT 5
Y DAT 10
TEMP DAT 0
Here, the values of VAR1 and VAR2 are passed using their names. This allows you to
pass arguments in any order.