KEMBAR78
Sorted Solution | PDF | Assembly Language | Macro (Computer Science)
0% found this document useful (0 votes)
4 views10 pages

Sorted Solution

Uploaded by

ganeshwagh.9.w
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views10 pages

Sorted Solution

Uploaded by

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

✅ Q1 a) Flowchart of Pass-I of Two Pass Assembler

1. Pass-I scans the source program line by line.


2. Initialize Location Counter (LC), SYMTAB, LITTAB, POOLTAB.
3. If the statement is START, set LC to operand value.
4. If a label is present, enter into Symbol Table with LC value.
5. If the statement is an instruction, generate intermediate code and
update LC.
6. If the operand is a literal, add it into Literal Table (address not assigned
yet).
7. If the operand is immediate, no entry in table, directly used.
8. If directive like ORIGIN, EQU → modify LC or symbol value.
9. At END, assign addresses to literals and update Pool Table.
10.Pass-I produces Intermediate Code (IC), SYMTAB, LITTAB, POOLTAB
as output.

✅ Q1 b) Literal vs Immediate Operand


1. Literal Operand: Value written with =’value’.
2. Immediate Operand: Value written directly.
3. Literal stored in Literal Table.
4. Immediate does not need table entry.
5. Literal address assigned at the end of program.
6. Immediate used directly by CPU.
7. Example literal: MOVER AREG, =’5’.
8. Example immediate: MOVER AREG, 5.
9. Literal is placed in memory.
10.Immediate value is part of instruction.

✅ Q2 a) Databases used in Assembler


1. SYMTAB: Stores symbols with addresses.
2. LITTAB: Stores literals (=’value’) with addresses.
3. POOLTAB: Manages literal groups in program.
4. MOT (Mnemonic Opcode Table): Holds opcodes, size, class (IS, DL, AD).
5. POT (Pseudo Opcode Table): Holds assembler directives (START, END,
ORIGIN).
6. SYMTAB helps resolve labels during translation.
7. LITTAB helps assign addresses to constants.
8. POOLTAB required when literals appear in different parts.
9. MOT ensures correct machine opcode generation.
10.POT ensures assembler directives are handled correctly.

✅ Q2 b) Algorithm of Pass-I of Two Pass Assembler


1. Initialize LC = 0, tables = empty.
2. Read source program line by line.
3. If START → set LC.
4. If label exists → enter in SYMTAB with LC.
5. If instruction → generate IC and increment LC.
6. If literal found → enter in LITTAB.
7. If directive like DS or DC → allocate memory, increment LC.
8. If EQU or ORIGIN → adjust LC.
9. If END → assign addresses to literals and complete POOLTAB.
10.Write Intermediate Code for Pass-II.

✅ Q1 a) Purpose of Pass-I
1. To assign addresses to instructions and data.
2. To build Symbol Table.
3. To build Literal Table.
4. To build Pool Table.
5. To identify assembler directives and process them.
6. To generate intermediate code.
7. To calculate instruction lengths.
8. To provide symbolic references for Pass-II.
9. To prepare data structures needed in Pass-II.
10.To simplify final translation into machine code.
✅ Q1 b) System vs Application Software & Benefits of Assembly
1. System Software: Manages hardware, e.g. OS, Compiler, Assembler.
2. Application Software: User-specific tasks, e.g. Word, Excel.
3. System software acts as platform for application software.
4. Application software cannot run without system software.
5. Assembly language is close to machine code.
6. Assembly provides faster execution.
7. Assembly gives full control over hardware.
8. Assembly reduces memory usage.
9. It is useful in embedded systems and device drivers.
10.Debugging is easier than binary machine code.

✅ Q2 a) Need of Intermediate Code


1. Used as output of Pass-I.
2. Contains symbolic references.
3. Simplifies Pass-II processing.
4. Stores opcodes in symbolic form.
5. Stores operands as symbols or literals.
6. Helps in relocation and linking.
7. Avoids repeated scanning of source.
8. Makes assembler design modular.
9. Used for error detection.
10.Bridges gap between source and machine code.

✅ Q2 b) Output of Pass-I
1. Intermediate Code generated.
2. SYMTAB created with symbols and addresses.
3. LITTAB created with literals and addresses.
4. POOLTAB created for literal pools.
5. MOT is referred for opcodes.
6. POT is referred for directives.
7. Location Counter values finalized.
8. All assembler directives processed.
9. Address assignment to symbols completed.
10.Data given to Pass-II for translation.

✅ Q1 b) Assembler vs Compiler
1. Assembler: Converts assembly → machine code.
2. Compiler: Converts high-level language → machine code.
3. Assembler works closer to hardware.
4. Compiler works at higher level of abstraction.
5. Assembler input = assembly program.
6. Compiler input = C, Java, etc.
7. Assembler produces object code.
8. Compiler produces object code or executable.
9. Assembler generally faster.
10.Compiler includes optimization phases.

✅ Q2 a) Output of Pass-I with tables


1. MOT: Stores instructions (e.g. MOVER → IS,04).
2. POT: Stores directives (START, END).
3. SYMTAB: Stores labels with addresses.
4. LITTAB: Stores literals with addresses.
5. POOLTAB: Stores literal pool indices.
6. Intermediate Code produced.
7. LC values maintained.
8. Each symbol resolved to address.
9. Literals placed in memory.
10.Data structures ready for Pass-II.

✅ Q2 b) Necessity of Data Structures in Pass-I


1. SYMTAB needed for storing symbols.
2. LITTAB needed for literals.
3. POOLTAB needed for literal management.
4. MOT needed for instruction translation.
5. POT needed for assembler directives.
6. Intermediate Code Table required for Pass-II.
7. Without tables, address resolution is impossible.
8. Tables make assembler efficient.
9. Tables help error detection.
10.Tables simplify machine code generation.

Great 👍 Let’s continue with Unit 2 answers in 10-point style (simple +


expanded enough for 7–8 marks).

✅ Unit 2
Q3 a) Define Macro. What are the advantages of macro facility? How
they are different from functions? ⭐
1. Macro: A single instruction in a program that represents a group of
instructions.
2. Defined using MACRO … MEND.
3. Macro Call: Invoked by its name, expanded inline.
4. Advantages:
o Saves programmer’s time (reusable).

o Improves readability of code.

o Avoids repetitive coding.

o No function call overhead (faster).

o Allows parameters to be passed.

5. Macros are processed by macro processor before assembly.


6. Expansion happens at compile/assembly time.
7. Function vs Macro:
o Function executes at runtime, Macro expanded at compile time.

o Function uses stack/return values, Macro does not.

o Function has overhead of call/return, Macro is inline.

8. Functions can return a value, macros cannot.


9. Functions save space (one copy only), macros increase program size
(expansion each time).
10.Macros are best for short, repetitive code fragments.

Q3 b) Short note on: i) Compiler, ii) Interpreter


i) Compiler:
1. Translates entire program from high-level language to machine code.
2. Errors are displayed after compilation is complete.
3. Generates object code/executable.
4. Execution is faster because code is pre-translated.
5. Example: C Compiler.
ii) Interpreter:
6. Translates source code line by line.
7. Stops at first error and displays immediately.
8. Does not generate separate object code.
9. Execution is slower due to translation at runtime.
10. Example: Python Interpreter.

Q4 a) Data structures for Two Pass Macro Processor


1. MNT (Macro Name Table): Stores macro names and pointers to MDT.
2. MDT (Macro Definition Table): Stores body of macro statements.
3. ALA (Argument List Array): Stores arguments passed in macro calls.
4. KPDTAB (Keyword Parameter Default Table): Stores keyword
parameters with default values.
5. EVNTAB: Stores expansion time variables (used in advanced macros).
6. MNT helps locate macro quickly.
7. MDT helps expand macro during Pass-II.
8. ALA ensures positional parameters are substituted properly.
9. KPDTAB handles flexibility by assigning default values.
10.Together these structures make macro expansion systematic.

Q4 b) Argument passing mechanism in Macros


1. Positional Parameters:
o Arguments are passed in order.
o Example:

o MACRO ADDXY &X,&Y

o ADD &X,&Y

o MEND

o ADDXY A,B → ADD A,B

2. Keyword Parameters:
o Arguments passed with names.

o Example:

o MACRO INCR &REG=AREG

o ADD &REG,1

o MEND

o INCR REG=BREG → ADD BREG,1

3. Macro processor stores arguments in ALA.


4. Positional parameters are replaced based on index.
5. Keyword parameters are replaced based on names.
6. Positional passing is simple but order-dependent.
7. Keyword passing gives flexibility.
8. Default values possible with keyword parameters.
9. Helps in code reuse with different arguments.
10.Provides modularity in assembly programs.

Q3 a) Macro definition, call and expansion


1. Definition: Macro is written using MACRO … MEND.
2. Example:
3. MACRO INCR &X
4. ADD &X,1
5. MEND
6. Macro Call: Invoked by using macro name in program.
Example: INCR AREG
7. Macro Expansion: Macro call replaced by body.
Example: Expands to → ADD AREG,1.
8. Expansion is done inline (no separate function call).
9. Multiple calls → each replaced with full body.
10.Processor uses MDT and ALA for expansion.
11.Macros reduce programmer’s effort.
12.Easy for repetitive tasks.
13.But expansion increases program size.

Q3 b) Differentiate:
i) Macro vs Subroutine
1. Macro expanded inline, Subroutine executed separately.
2. Macro has no call overhead, Subroutine requires call/return.
3. Macro increases code size, Subroutine saves space.
4. Macro faster (no runtime call), Subroutine slower.
5. Macro arguments replaced at compile time, Subroutine uses
stack/registers.
ii) Compiler vs Interpreter → Already answered in Q3b.

Q4 a) Phases of Compiler for x = I + R * 60 (R float)


1. Lexical Analysis: Converts into tokens (x, =, I, +, R, *, 60).
2. Syntax Analysis: Builds parse tree for expression.
3. Semantic Analysis: Checks types (R is float → conversion).
4. Intermediate Code Generation: Produces code like:
o t1 = R * 60

o t2 = I + t1

o x = t2

5. Code Optimization: Removes unnecessary instructions.


6. Code Generation: Converts into target machine code.
7. Each phase has its own output.
8. Lexical output → tokens.
9. Syntax output → tree.
10.Semantic + code generation → machine code.

Q4 b) Algorithm of Pass-I of Macro Processor


1. Initialize MNT, MDT, ALA, KPDTAB.
2. Read source program line by line.
3. If line is not a macro definition → copy to intermediate code.
4. If line is MACRO directive → start macro definition.
5. Enter macro name in MNT with pointer to MDT.
6. Store macro body in MDT.
7. Store positional/keyword parameters in ALA/KPDTAB.
8. Continue until MEND encountered.
9. Repeat process for other macros.
10.Pass-I output = MNT, MDT, ALA, KPDTAB, and intermediate code.

Q3 a) Phases of Compiler and their output


1. Lexical Analysis: Input → source program, Output → tokens.
2. Syntax Analysis: Input → tokens, Output → parse tree.
3. Semantic Analysis: Input → parse tree, Output → checked tree with
types.
4. Intermediate Code Generation: Output → three address code.
5. Code Optimization: Output → optimized code.
6. Code Generation: Output → machine code.
7. Example: A = B + C * D.
8. Tokens = {A, =, B, +, C, *, D}.
9. Intermediate code = t1 = C*D; t2 = B+t1; A=t2.
10.Final → machine instructions.

Q3 b) Macro advantages and difference from function ⭐ → Already


answered in Q3a.

Q4 a) Use of AIF and AGO


1. AIF (Assembly IF): Used for conditional branching in macros.
2. Syntax: AIF (condition).label
3. If condition true, macro expands from that label.
4. Example: AIF (&X GT 0).POS
5. AGO (Assembly GO): Used for unconditional branch.
6. Syntax: AGO .label
7. Transfers control to label in macro body.
8. Helps in repeating or skipping parts in macros.
9. Macro Expansion with Positional Parameters: arguments substituted by
position.
10.Example: ADDXY A,B expands to ADD A,B.

Q4 b) Single Pass Macro Processor


1. Expands macros in one pass only.
2. No separate pass for definition and expansion.
3. Processes macro definition and expansion simultaneously.
4. Faster but more complex than two-pass.
5. Suitable when program is small.
6. Example:
7. MACRO OUTER &X
8. LOAD &X
9. INNER &X
10.MEND
11.
12.MACRO INNER &Y
13.ADD &Y,1
14.MEND
15.OUTER AREG
16.Expands immediately:
17.LOAD AREG
18.ADD AREG,1
19.Nested macros also expanded in same pass.
20.Reduces time as no intermediate storage.
21.But harder to implement due to inline processing.

You might also like