1 / 33

Chapter IV: Macro Processors

Overview: To study the design and implementation of macro processors. A macro represents a commonly used group of statements in the source programming language. The macro processor replaces each macro instruction with the corresponding group of source language statements. (expanding) .

karan
Download Presentation

Chapter IV: Macro Processors

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. Overview: To study the design and implementation of macro processors. A macro represents a commonly used group of statements in the source programming language. The macro processor replaces each macro instruction with the corresponding group of source language statements. (expanding) Chapter IV: Macro Processors 4. Macro Processors

  2. Macro definition Invocation Expansion (with substitution of parameters) Basic macro processor functions 4. Macro Processors

  3. Basic macro processor functions • Macro definition • Invocation • Expansion (with substitution of parameters) 4. Macro Processors

  4. Basic macro processor functions • Macro definition • Invocation • Expansion (with substitution of parameters) 4. Macro Processors

  5. 4. Macro Processors

  6. Use of macros in a SIC/XE program 4. Macro Processors

  7. Use of macros in a SIC/XE program (cont.) 4. Macro Processors

  8. Program from above with macros expanded 4. Macro Processors

  9. Program from above with macros expanded (cont.) 4. Macro Processors

  10. Discussions… • Why does macro statement use JLT *-14? • Allow label? 4. Macro Processors

  11. Macro processor algorithm and data structures • For one-pass macro processor, the definition of a macro must appear in the source program before any statements that invoke that macro. • Three important tables are used for the macro processor: NAMTAB、DEFTAB、and ARGTAB. 4. Macro Processors

  12. Macro processor algorithm and data structures(cont.) 4. Macro Processors

  13. Macro processor algorithm and data structures 4. Macro Processors

  14. Macro processor algorithm and data structures (cont.) 4. Macro Processors

  15. Macro processor algorithm and data structures (cont.) 4. Macro Processors

  16. Machine-Independent Macro Processor Features---- Concatenation of Macro Parameters • This feature enable a program to generate a series of variables named by XA1, XA2, XA3, …, etc. and XB1, XB2, XB3, …, etc. as well. • The body of the macro definition might contain a statement like LDA X&ID1 • It has some problems!! (solution: concatenation operator) 4. Macro Processors

  17. Machine-Independent Macro Processor Features---- Concatenation of Macro Parameters (cont.) 4. Macro Processors

  18. Machine-Independent Macro Processor Features---- Generation of unique labels • In general, the body of a macro instruction that contains labels is not possible. • It will cause duplicate definition. • Solution: use relative addressing (e.g., JEQ *03) • Drawback: For short jump, it is acceptable. For longer jump, it is not convenient, error- prone, and difficult to read . 4. Macro Processors

  19. Machine-Independent Macro Processor Features---- Generation of unique labels (cont.) 4. Macro Processors

  20. Machine-Independent Macro Processor Features---- Generation of unique labels (cont.) 4. Macro Processors

  21. Machine-Independent Macro Processor Features---- Conditional Macro Expansion • For previous examples of macro instructions, these statements could be varied by the substitution of parameters, but the form of the statement, and the order in which they appeared, were unchanged. • Conditional macro expansion adds greatly to the power and flexibility of a macro language. 4. Macro Processors

  22. Machine-Independent Macro Processor Features---- Conditional Macro Expansion (cont.) 4. Macro Processors

  23. Machine-Independent Macro Processor Features---- Conditional Macro Expansion (cont.) Ps. &EORCK is a macro-time variable. 4. Macro Processors

  24. Machine-Independent Macro Processor Features---- Conditional Macro Expansion (cont.) 4. Macro Processors

  25. Machine-Independent Macro Processor Features---- Conditional Macro Expansion (cont.) 4. Macro Processors

  26. Machine-Independent Macro Processor Features---- Macro-time looping statements 4. Macro Processors

  27. Machine-Independent Macro Processor Features---- Macro-time looping statements (cont.) 4. Macro Processors

  28. Machine-Independent Macro Processor Features---- Keyword Macro Parameters • Positional parameter vs. Keyword parameterGENER , , DIRECT, , , , , , 3.GENER TYPE=DIRECT, CHANNEL=3. 4. Macro Processors

  29. Machine-Independent Macro Processor Features---- Keyword Macro Parameters (cont.) 4. Macro Processors

  30. Machine-Independent Macro Processor Features---- Keyword Macro Parameters (cont.) 4. Macro Processors

  31. Machine-Independent Macro Processor Features---- Keyword Macro Parameters (cont.) 4. Macro Processors

  32. Macro Processor Design Options---- Recursive Macro Expansion • The invocation of one macro, which is defined by another macro instruction. • Using a programming language that allows recursive calls to write the macro processor. 4. Macro Processors

  33. 4. Macro Processors

More Related