660 likes | 850 Views
Macro Processor: Macro Definition and call, Macro Expansion, Nested Macro Calls and definition, Advanced Macro Facilities, Design of Macro Processor. Introduction. A macro is a facility for extending a programming language.
E N D
Macro Processor: • Macro Definition and call, • Macro Expansion, • Nested Macro Calls and definition, • Advanced Macro Facilities, • Design of Macro Processor Sytem Programming
Introduction • A macro is a facility for extending a programming language. • A macro represents a commonly used group of statements in the source programming language • Each time this name Occurs in a program, the sequence of codes is substituted at that point. • It allows the programmer to write shorthand version of a program .
Example | | | ADD 1,DATA ADD 2,DATA ADD 3,DATA | | | ADD 1,DATA ADD 2,DATA ADD 3,DATA | | DATA DC 5
Macro • 3 main step of macro 1.Deifine the macro name 2. Write its definition 3.Use the macro name from with in the program anywhere its definition • Macro Definition • Two new assembler directives • MACRO • MEND
Macro Instruction with parameter Syntax Start of definition……………………….. MACRO Macro name with parameter…………………………… Sequence of instruction………….. { End of definition……………………………...MEND Example: MACRO INCR &ARG ADD AREG,&ARG ADD AREG,&ARG ADD AREG,&ARG MEND
Types of Macro Expansion • 1.Lexical Expansion • 2.Semiantic Expansion 1.Lexical Expansion: Character string is replaced by another character string in the generation of program. All formal parameter is replaced by actual parameter. 2.Semiantic Expansion : Instruction as per requirement of specific usage are generated.
MACRO: is the first line of the definition & identifies the following line as the macro instruction name. • The definition is terminated by with MEND statement • Macro call : macro processor replaces each macro call with macro instruction .
Example Source program Expanded Source | MACRO INCR ADD 1,DATA ADD 2,DATA ADD 3,DATA MEND | INCR ADD 1,DATA | ADD 2,DATA INCR ADD 2,DATA | | ADD 1,DATA | ADD 2,DATA ADD 2,DATA DATA DC 5
Difference between macro and subroutine: • Difference between macro and subroutine: 1. a macro call is an instruction to replace the macro name with its body, whereas subroutine call is an instruction to transfer the program’s control to the subroutine’s definition with all paraneters, if required.2. A macro call results in macro expansion, whereas subroutine call results in execution.3. Macro expansion increases the size of the program but subroutine execution doesn’t affect the size of the program4. Macro expansion doesn’t affect the execution speed of the program much in comparison to subroutines affect the execution speed of the program
Example: MACRO INCR &X, &Y, ®=AREG MOVER ®, &X ADD ®, &Y MOVEM ®, &X MEND MACRO DECR &X, &Y, ®=BREG MOVER ®, &X SUB ®, &Y MOVEM ®, &X MEND
START 100 READ N1 READ N2 INCR N1,N2,REG=CREG DECR N1, N2 STOP N1 DS 1 N2 DS 1 END
Advanced Macro Facilities • Advanced Macro Facilities are basically used to enhance the semantic macro Expansion