Tuesday, March 20, 2012

System Software - Question Bank - Unit - IV

MC9224 - System Software - Question Bank

Unit I & Unit II                              Unit - III

UNIT - IV

1.      What is the operation of macroprocessor?
A macroinstruction is simply a notational convenience for the programmer. A macro represents a commonly used group of statements in the source programming language. The macro processor relocates each macroinstruction with the corresponding group of source language statements. This called expanding macros.
The function of a macro processor essentially involves the substitution of one group of characters or lines for another.

2. Write notes on macro definition and expansion?
Two assembler directives are used in macro definitions. The first MACRO statement identifies the beginning of a macro definition. The second MEND assembler directive marks the end of the macro definition.
RDBUF MACRO &INDEV,&BUFADR,&RECLTH
TD =X’ &INDEV’
MEND

In the above source code, the symbol in the label field (RDBUF) is the name of the macro, and the entries in the operand field identify the parameters of the macroinstruction.
   
 3. What are the data structures involved in macro processor?
DEFTAB – macro definition table, the macro definitions are stored in this table. NAMTAB – macro names are entered into this table. It is served as the index to DEFTAB. ARGTAB – argument table, which is used during the expansion of macro invocation.

4. Write the procedure PROCESSLINE in the one-pass macro processor algorithm?

       Procedure PROCESSLINE Begin Search NAMTAB for OPCODE
If found then
EXPAND
Else if OPCODE = ‘MACRO’ then
DEFINE
Else write source line to expanded file
end

5.   What are the features of machine independent macro processors?
The various features are
·         Concatenating macroinstruction parameters with other character strings.
·         Generating unique labels within macro expansions, which avoid the need for extensive use of relative addressing.
·         Macro expansions. This ability is to alter the expansion of a macro by using control statements.
·         The definition and use of keyword parameters in macroinstructions.

6.   How concatenation of macro parameters is performed?
Most macro processors allow parameters to be concatenated with other character strings. The following statement will do the concatenation
DA X&ID1
In which the parameter &ID is concatenated after the character string X and before the character string 1.
One problem about this is that the beginning of the macro parameter is identified by the starting symbol & , however the end of the parameter is not marked.
Most macro processors deal with this problem by providing a special concatenation operator. In SIC macro language, this operator is the character . Thus the previous statement would be written as
LDA X&ID1

7.   Write notes on generation of unique labels in macroprocessors?
The duplicate definition would prevent correct assembly of the resulting expanded program. Many macro processors avoid these problems by allowing the creation of special types of labels within macro instructions.
Labels used within the macro body begin with the special character $. Each symbol beginning with $ has been modified by replacing $ with $AA. More generally the character $ will be replaced by $xx, where xx is a two character alphanumeric counter of the number of macro instruction expanded. For example AA,AB,AC, etc.

8. Write the conditional statement in macros?
The use of macro time variable makes it clear that the same logical condition is involved in to IF statements. Examining the values of the variable may also be faster than repeating the original test.
The implementation of conditional macro expansion is very simple. The macro processor must maintain a symbol table that contains the values of all macro time variables used. The table is used to look up the current value of a macro time variable whenever it is required.
The testing of Boolean expression in IF statements occur at the time macros is expanded.

9. Write notes on WHILE statement in macros?.
The WHILE statement specifies that the following lines , until the next ENDW statement ate to be generated repeatedly as long as the looping are done while true.
Ex:
WHILE (&CTR � &EORCT)

ENDW
When a WHILE statement is encountered during macro expansion, the specified Boolean expression is evaluated. If the value of this expression is FALSE the macro processor skips ahead until it finds the next ENDW statement, and then resumes normal macro expansion. If the value of this expression is TRUE, the macro processor continues to processes lines in the usual way until the next ENDW statement. Then proceed to the WHILE for revaluation.
This method does not allow for nested WHILE structures.

10. Write notes on conditional macro expansion?
Most macro processors, however, can also modify the sequence of statements generated for a macro expansion, depending on the arguments supplied in the macro invocation.
The term conditional assembly is commonly used to describe this feature.

11. Define macro time variable?
&EORCK SET 1
The symbol &EORCK is a macro time variable, which can be used to store working values during the macro expansion. Any symbol that begins with the character & and that is not a macro instruction parameter is assumed to be a macro-time variable. All such variables are initialized to a value of 0.
The use of macro time variable makes it clear that the same logical condition is involved in to IF statements. Examining the values of the variable may also be faster than repeating the original test.

12. Write notes on positional parameters in macroprocessors?
The macro definitions defined in ordinary way are positional parameters. That is, the parameters and arguments were associated with each other according to their positions in the macro prototype and the macro invocation statement.
GENER ,,DIRECT,,,,,3.

13. Write notes on Keyword parameters in macroprocessors?
If a macro has a large number of parameters, and only a few of these are given values in a typical invocation. A different form of specification is useful. This is called keyword parameters. In keyword parameters each argument value is written with a keyword that names the corresponding parameters.
RDBUF MACRO &INDEV = F1, &BUFADR=, &RECLTH=, &EOR = 04, &MAXLTH = 4096
14. How to invoke the macro which has keyword parameters?
In the macro prototype, each parameter name is followed by an equal sign, which identifies a keyword parameter. After the equal sign, a default value is specified for some of the parameters. The parameter is assumed to have this default value if its name does not appear in the macro invocation statement.
GENER TYPE = DIRECT,CHANNEL = 3.

15. How to define one macro instruction in another macro?

16. How to invoke a macro by another by another macro?

It is also possible to define one macro instruction in another macro.
MACROS
MACRO
{ ---}
RDBUF
MACRO
&INDEV,&BUFADR,&RECLTH







MEND





MEND


The invocation of macro by another is as follows RDBUF MACRO &BUFADR, &RECLTH, &INDEV
RDCHAR &INDEG
MEND

17. What happened when we apply one pass macro processor algorithm for invocating a macro by another macro?
When we apply the one pass macro processor algorithm for invocation of a macro by another in the above macro code, the procedure EXPAND would be called when the macro was recognized. The arguments from the macro invocation would be entered into ARGTAB. The Boolean variable EXPANDING would be set to TRUE, and expansion of the macro invocation would begin.

18. Write notes on general purpose macro processors?
These are not depend on any particular programming language, but can be used with a variety of different languages. Advantage of general purpose of macro processor is that the programmer does not need to learn about a different macro facility for each compiler of assembler language, so much of the time and expenses involved in training are eliminated.

19. What are the problems in general purpose macro processors?
A more general problem involves the tokens of the programming language. The restriction on the length of identifiers and the rules for the formation of constants. Another problem is the syntax used for macro definitions and macro invocation statements.

20. What is a line by line macro processor?
Using this approach, the macro processor reads the source program statements and performs all of its function as usual. However, the output lines are passed to the language translator as they are generated, instead of being written to an expanded source file.

21. What are the advantages of line-by-line macro processor?
It avoids making an extra pass over the source program, so it can be more efficient than using a macro preprocessor. Some of the data structures required by the macro processor and the language translator can be combined. A line-by-line macro processor can also makes it easier to give diagnostic messages that are related to the source statement containing error.

22. What is an integrated macro processor?

The main form of communication between the two functions is the passing of source statements form one to another. It is possible to have even closer cooperation between the macroprocessor and the assembler or compiler. Such a scheme can be thought of as a language translator with an integrated macro processor.
An integrated macro processor can potentially make use of any information about the source program that is extracted by the language translator.

23. Write notes on MASM Macro processor?
The macro processor of MASM is integrated with pass1 of the assembler. It supports all of the main macro processor functions, including the definition and invocation of macro instructions within macros.
The comment line which begins with ;; is a macro comment. It serves only as documentation for the macro definition, it is ignored when the macro is expanded. The comment line begins with ; is an ordinary assembler language comment.

24. Write notes on ANSI C Macro language?
In the ANSI C language, definition and invocations of macros are handled by a preprocessor. This preprocessor is generally not integrated with the rest of the compiler.
Two exampled of ANSI definitions are
# define NULL 0
# define EOF (-1)

After these definitions appear in the program, every occurrence of NULL will be replaced by 0, and every occurrence of EOF will be replaced by (-1).
ANSI macros can also be defined with parameters.
# define ABSDIFF(X,Y) ((X) > (Y) ? (X) – (Y) : (Y) –(X) )

25. Write notes on ELENA Macro processor?
ELENA was developed as a research tool, not as a commercial software product.
Macro definitions in ELENA are composed of a header and a body, as with most macro processors. It consists of a sequence of keyword and parameter markers.
ELENA also provides macro-time variables and macro-time instructions that can be used to control the macro expansion.
The ELENA macro processor uses a macro definition table that is similar to the one we discussed for SIC. The macro is identified by the sequence of keywords that appear in its header.

3 comments: