Sie sind auf Seite 1von 8

MACROS

Ques. What is a Macro? Ans. Macros are single line abbreviations for group of instructions, which are used again and again in the program code. They are used to shorten the code length of the program and also they help to avoid the repetition. . In employing a macro, the programmer essentially defines a single instruction to represent a block of code. For every occurrence of this one line macro instruction in the program code, the macro processing assembler will substitute the entire block. Ques. What are the advantages of the macro instructions? Ans . The advantages of macros are: 1The macro operations simplify debugging and program modification and they facilitate standardization. 2By defining the macros, the programmer can achieve the conciseness and ease in coding of the high level language without losing the basic advantage of the assembly language. Ques: What are the various formats of databases while designing a two pass macro processor? Ans. The various formats of databases while designing a two pass macro processor are1ARGUMENT LIST ARRAY (ALA):ALA is used during both pass 1 and pass2.During pass 1 dummy arguments in macro definition are replaced with positional indicators when the definition is stored. The dummy argument on the macro name card is represented by the index marker symbol#. These symbols are used in conjunction with argument list as prepared before macro expansion. During pass 2 the macro call arguments for index markers stored in macro definition table are substitute. Thus upon encountering the macro call, the macro expander would prepare an ALA. 2MACRO DEFINATION TABLE (MDT):MDT is a table of text lines. Every line of each macro definition except MACRO line is stored in MDT. The MEND is kept to indicate the end of definition; and the macro name line is retained to facilitate keyword argument replacement. 3MACRO NAME TABLE ( MNT): Each entry of MNT consist of a character string i.e. the macro name and pointer(index) to the entry in MDT that corresponds to the beginning of the macro definition. MACRO DEFINITION CARDS 0 &ARG2,&ARG3 1 TABLE (MDT) INCR A INDEX &ARG1, 1, #1 2

A MEND

2, #2

3, #3

MACRO NAME TABLE (MNT) MDT index 0 INCR

INDEX 0

NAME

ARGUMENT LIST ARRAY FOR PASS 1 ARGUMENT LIST ARRAY (ALA) Index Arguments 0 DATA 1bbb 1 L O OP1bbb 2 DATA 2bbb 3 DATA 3bbb ARGUMENT LIST ARRAY FOR PASS 2 ARGUMENT LIST ARRAY (ALA) INDEX ARGUMENT 0 bbbbbbbbb 1 DATA3bbb 2 DATA2bbb 3 DATA1bbb Ques Explain a two pass macro processor with the help of algorithm? Ans In a two pass macro processor there are two passes. Pass one is meant for macro definition and pass two for macro calls and expansion. The algorithm for pass one and two are: ALGORITHM In the Figures given below we have the flow charts of the macro definition and expansion algorithms. Each of the algorithms makes a line-by-line scan over its input. The READ Boxes refer to the fetching of successive input lines from secondary storage into workspace. PASS 1- MACRO DEFINATION: The algorithm for pass 1 tests each input line. If it is a MACRO pseudo-op, the entire macro definition that follows is saved in the next available locations in the Macro Definition Table (MDT). The first line of the definition is the Macro name line. The name is entered into the Macro Name Table (MNT), along with a pointer to the first location of the MDT entry of the definition. When the END psuedo-op is encountered, all of the Macro definitions have being processed so control transfer to PASS 2 in order to process the macro calls. PASS 2 - MACRO CALLS AND EXPANSION: The algorithm for the PASS 2 tests the operation mnemonics of each input line to see if it is the name in the MNT. When the call is found, the call processor sets the pointer, The MACRO DEFINATION TABLE POINTER (MDTP), to the corresponding Macro

definition stored in the MDT. The initial value of the MDTP is obtained from the MDT index field of the MNT entry. The macro expander prepares the argument list Array (ALA) consisting of a table of dummy arguments on the name card (the first is the label arguments, which is considered to have an index of zero) Arguments not represented in a call are considered blank, and superfluous arguments are ignored. In the case of references by position, this scheme is completely straight forward, for reference by name, the macro processor locates the dummy arguments on the macro name line (which is available in the beginning of the definition in the MDT) in order to determine the proper index. Reading proceeds from the MDT; as each successive line is read, the values from the arguments list are substituted for the dummy arguments indices in the macro definition. Reading of the MEND line in the MDT terminates expansion of the macro, and scanning continuous from the input file. When the END psuedo-op is encountered, the expanded source desk is transferred to the assembler for the father processing. Ques. What are conditional macros? Ans Conditional macros are the macros that executes only when the condition is satisfied. There are two types of conditional macros1.AIF 2.AGO 2.AIF conditional macro:-AIF executes only when the conditions are satisfied and if the condition is false, it ends up the loop. So AIF is a basically a conditional pseudo-op. An AIF statement has the syntax AIF (<expression>) <sequencing symbol> 2.AGO conditional macro:-AGO statement is similar to a GO TO statement. AGO statement helps in switching from one line to another. It does not follow any condition. An AGO statement has the syntax AGO <sequencing symbol>

Ques. Draw flow charts of two pass macro processor? Ans.

Ques. What are the various specifications of the Data Bases? Ans. Specifications of Data Bases The following data bases are used by the two passes of the macro processor : Pass 1 Data Bases: 1.The input macro source deck. 2.The output macro source deck copy for use by pass 2. 3.The macro definition table MDT used to store the body of the macro definitions. 4.The macro name table MNT used to store the name s of the defined macros. 5.The macro definition table counter MDTC used to indicate the next available entry in the MDT. 6.The macro name table counter MNTC used to indicate the next available entry in the MNT. 7.The argument list array ALA used to substitute index marker for dummy arguments before storing a macro definition. Pass 2 Data Bases: 1.Copy of the input macro source deck. 2.The output expanded source deck to be used as input to the assembler. 3.The macro definition table MDT created by Pass 1 4.Macro name table MNT created by pass 1 5.Macro definition table pointer MDTP used to indicate the next line of the text to be used during macro expansion. 6.The argument list array ALA used to substitute macro call arguments for the index makers in the stored macro definition. Ques. What are the various tasks that any macroinstruction processor must perform? Ans. There are basically four tasks that any macro instruction processor must perform they are: 1.Recognize Macro definitions: A macroinstruction processor must recognize macro definitions identified by the MACRO and the MEND psuedo-ops. This task can be complicated when the macro definitions appears within macros. This is when MACRO and MEND are nested. 2.Save the definitions: The processor must store the macroinstruction definitions, which it will need for expanding macro calls. 3.Recognize calls: The processor must recognize the macro calls that appear as operation mnemonics. This suggests that macro names be handled as a type of Op-code. 4.Expand calls and substitute arguments: The processor must substitute for the dummy or macro definition arguments the corresponding arguments from a macro call; the resulting symbolic ( in this case assembly language ) text is then substituted for the macro call. This text may contain additional macro definitions or calls.

Ques. Describe input and output of a macro processor. How is it dependent over the assembly code? Ans. The macro processor makes two `semantic scans over the input text, searching first for the macro definitions and then for the macro expansions. So pass one of the macro processor relates to the input operations that is inputting the macro definitions and pass two of the macro processor is related to output task of considering the macro call and expanding the macro which outputs the contents of the macro definition. The macro processor can be added as a preprocessor to an assembler, making a complete pass over input text before pass 1 of the assembler. The implementation of macro processor over the pass 1 eliminates the over head of the intermediate files, and we can improve this integration of this macro processor and the assembler by combining similar functions. Ques. What are Nested Macros? Ans. The model statement in a macro may constitute a call on another macro. Such calls are known as nested macro calls. The macro containing the nested call is known as the outer macro and the called macro is known as the inner macro. Expansion of nested macro calls follows the last -in-first out (LIFO) rule.Thus, in a structure of nested macro calls, expansion of the latest macro call (i.e the innermost macro call in the structure) is completed first. eg:MACRO INCR MACRO ADD A 1,DATA A 2,DATA MEND. MEND. Ques. Explain the design of a macro preprocessor? Ans. The macro preprocessor accepts an assembly program containing definitions and calls and translates it into an assembly program which does not contain any macro definitions or calls. The program form output by the macro preprocessor can now be handed over to an assembler to obtain the target language form of the program.

Das könnte Ihnen auch gefallen