1 / 58

Macro Processor: Macro Definition and call, Macro Expansion,

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.

dennisj
Download Presentation

Macro Processor: Macro Definition and call, Macro Expansion,

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Macro Processor: • Macro Definition and call, • Macro Expansion, • Nested Macro Calls and definition, • Advanced Macro Facilities, • Design of Macro Processor Sytem Programming

  2. 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 .

  3. Example | | | ADD 1,DATA ADD 2,DATA ADD 3,DATA | | | ADD 1,DATA ADD 2,DATA ADD 3,DATA | | DATA DC 5

  4. 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

  5. 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

  6. 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.

  7. 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 .

  8. 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

  9. 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

  10. Example: MACRO INCR &X, &Y, &REG=AREG MOVER &REG, &X ADD &REG, &Y MOVEM &REG, &X MEND MACRO DECR &X, &Y, &REG=BREG MOVER &REG, &X SUB &REG, &Y MOVEM &REG, &X MEND

  11. START 100 READ N1 READ N2 INCR N1,N2,REG=CREG DECR N1, N2 STOP N1 DS 1 N2 DS 1 END

  12. Advanced Macro Facilities • Advanced Macro Facilities are basically used to enhance the semantic macro Expansion

  13. No operation is carried out by an ANOP instruction.

  14. No operation is carried out by an ANOP instruction.

  15. The length of A is 1.

  16. Used to create number of similar statement.

More Related