SPCC Ia1
SPCC Ia1
SPCC Ia1
ANS)
2) explain macro and macro expansion , list differet feateus of macro with example
ANS)
A macro in the context of System Programming and Compiler Construction (SPCC) is
essentially a single instruction that expands into a set of instructions to perform a particular task.
Macro expansion is the process of replacing the macro instruction with the actual set of
instructions it represents.
Macro Expansion:
When a macro processor encounters a macro instruction in the source code, it replaces it with
the corresponding set of instructions. This process is called macro expansion. Macro expansion
helps to make the code more readable and maintainable by abstracting complex sets of
instructions into single, high-level commands.
Features of Macros:
1. Abstraction: Macros can encapsulate complex code into a single line, making the code
cleaner and more abstract.
2. Code Reusability: Once defined, macros can be reused throughout the code, which
helps avoid repetition.
3. Efficiency: Using macros can make the code more efficient by reducing the number of
lines and thus the size of the code.
4. Parameterization: Macros can accept parameters, making them more flexible and
powerful.
5. Conditional Compilation: Macros can include preprocessor directives for conditional
compilation, allowing the inclusion or exclusion of code based on certain conditions.
1. Start of Pass 2:
○ The macro processor begins its second pass, which is focused on expanding
macro calls.
2. Read the Next Source Card:
○ The processor reads the next line (source card) from the input file that was
prepared during Pass 1.
3. Search in Macro Name Table (MNT):
○ It searches the Macro Name Table (MNT) for a match to determine if the
operation code on the source card is a macro call.
4. Macro Name Found Check:
○ If a macro name is found in the MNT, it proceeds with expansion. If not, the line is
written to the expanded source file as it is, as no macro expansion is needed.
5. Set Up Argument List Array:
○ Once a macro name is identified, the processor sets up an array to hold the
arguments passed in the macro call.
6. Macro Definition Table Pointer (MDTP) Adjustment:
○ The MDTP is set to the index from the MNT entry, pointing to the correct location
in the Macro Definition Table (MDT) to begin macro expansion.
7. Increment MDTP:
○ The MDTP is incremented to get the next line from the MDT.
8. Get Line From MDT:
○ The processor fetches the line from the MDT, which contains the macro template
to be expanded.
9. Substitute Arguments:
○ The arguments from the macro call are substituted into the macro template.
10. Check for MEND:
○ If the line fetched is the 'MEND' pseudo-operation, indicating the end of the
macro definition, the processor will loop back to read the next source card. If it's
not 'MEND', it means there are more lines to be processed for this macro, and
the processor continues to substitute arguments and expand.
11. Write Expanded Source Card:
○ The expanded source lines are written out to the expanded source file.
12. END Pseudo-op Check:
○ If the 'END' pseudo-operation is encountered, this indicates the end of the source
file.
13. Supply Expanded Source File:
○ The fully expanded source file is now ready to be supplied to the assembler for
further processing.
This second pass is critical because it translates macro instructions into the actual code that the
assembler can understand. The MNT and MDT are used to keep track of the macros and their
definitions, and the arguments are substituted into the macro body to create the expanded code.
This process is repeated for each macro call in the source file until all have been expanded.
4) explain different types of statement used in assembly with respect to system programming
ANS)
ANS)
Compiler Interpreter
Compiler can check syntactic and Interpreter checks the syntactic errors
semantic errors in the program only.
simultaneously.
ANS)
Macro Processor: A macro processor is a software tool that allows for text substitution and
expansion of predefined patterns, known as macros, within source code. Macros are typically
used to abstract code patterns that are used repeatedly throughout the program. The macro
processor expands these patterns into the specific sequences of code they represent before the
program is compiled or assembled.
Loader: A loader is a part of the operating system that loads executable files from storage into
memory to be run on the CPU. It sets up the initial execution context (like stack, heap, and
initialized data) and transfers control to the loaded program. The loader may also perform
relocation and linking of dynamic libraries at runtime if necessary.
Linker: A linker is a utility that combines multiple object files generated by a compiler into a
single executable program. The linker resolves references between the object files, assigns final
memory addresses to functions and variables, and handles external symbols by resolving them
to the correct addresses within other modules or libraries.
Each component plays a crucial role in the software development process, from writing code in
high-level or assembly languages to executing it on a machine. Assemblers, compilers, and
interpreters handle the translation of code, macro processors provide convenience in code
writing, and loaders and linkers manage the organization and execution of code at the system
level.