CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 11–Macro-Processors.

Slides:



Advertisements
Similar presentations
COP 3402 Systems Programming
Advertisements

Intermediate Code Generation
Macro simple idea of textual substitution useful when you need a group of instructions or directives frequently.
The Assembly Language Level
Chapter 3 Loaders and Linkers
Macro Processor.
SYSTEM PROGRAMMING & SYSTEM ADMINISTRATION
Macro Processors (MP) Macro: Macro Processors (MP): Examples:
1 Macro Processors. 2 Macro Processor l Recognize macro definitions l Save the macro definition l Recognize macro calls l Expand macro calls Source Code.
1 Machine-Independent Features Automatic Library Search automatically incorporate routines from a subprogram library Loading Options.
Chih-Hung Wang Chapter 2: Assembler (Part-1) 參考書目 Leland L. Beck, System Software: An Introduction to Systems Programming (3rd), Addison-Wesley, 1997.
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
VBA Modules, Functions, Variables, and Constants
An introduction to systems programming
Program Design and Development
1 Chapter 4 Macro Processors Source Code (with macro) Macro Processor Expanded Code Compiler or Assembler obj.
Chapter 4 Macro Processors
Introduction to a Programming Environment
1. 2 FUNCTION INLINE FUNCTION DIFFERENCE BETWEEN FUNCTION AND INLINE FUNCTION CONCLUSION 3.
Guide To UNIX Using Linux Third Edition
1 Chapter 4 Macro Processors Professor Gwan-Hwan Hwang Dept. Computer Science and Information Engineering National Taiwan Normal University 9/17/2009.
Macro & Function. Function consumes more time When a function is called, the copy of the arguments are passed to the parameters in the function. After.
Dr Masri Ayob TK 2633: Microprocessor & Interfacing Lecture 7: Assembly Language.
A Simple Two-Pass Assembler
© The McGraw-Hill Companies, 2006 Chapter 4 Implementing methods.
Assembler Design Options
Assemblers.
Chapter 1 Computer architecture Languages: machine, assembly, high
An introduction to systems programming
Machine Independent Macro Processor Features Concatenation of Macro Parameters Generation of Unique Labels Conditional Macro Expansion Keyword Macro.
4. Macro Processors1 Chapter IV: Macro Processors Overview: r To study the design and implementation of macro processors. r A macro represents a commonly.
PART I SISTEM UTILITIES LECTURE 5 MACROPROCESSING Ştefan Stăncescu 1.
Objective At the conclusion of this chapter you will be able to:
Ass. Prof. Dr Masri Ayob TK 6123 Lecture 13: Assembly Language Level (Level 4)
ICS312 Set 14 MACROS. Macros The program structure is similar to that for procedures. As for procedure names, macro names represent a group of instructions.
Microprocessor and Microcontroller Based Systems Instructor: Eng.Moayed N. EL Mobaied The Islamic University of Gaza Faculty of Engineering Electrical.
Assembly Language for x86 Processors 7th Edition Chapter 13: High-Level Language Interface (c) Pearson Education, All rights reserved. You may modify.
2 : Assembler 1 Chapter II: Assembler Chapter goal: r Introduce the fundamental functions that any assembler must perform. m Assign machine address m Translate.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Macro Processors.
Processor Fundamentals Assembly Language. Learning Objectives Show understanding of the relationship between assembly language and machine code, including.
Macro Processors Basic Functions Machine-Independent Features Design Options Implementation Examples.
 A macro represents a commonly used group of statements in the source programming language.  The macro processor replaces each macro instruction with.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Preocedures A closer look at procedures. Outline Procedures Procedure call mechanism Passing parameters Local variable storage C-Style procedures Recursion.
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 10 – Loaders.
1 Chapter 4 Macro Processors. 2 Introduction A macro instruction (abbreviated to macro) is simply a notational convenience for the programmer. A macro.
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 12–Compilers.
Macro Processor Design Options Recursive Macro Expansion General-Purpose Macro Processors Macro Processing within Language Translators.
Chapter 9: Value-Returning Functions
Programming what is C++
FUNCTIONS In C++.
System Programming and administration
Prof: Dr. Shu-Ching Chen TA: Samira Pouyanfar Hector Cen Fall 2017
Scripts & Functions Scripts and functions are contained in .m-files
Programmazione I a.a. 2017/2018.
MACRO Processors CSCI/CMPE 3334 David Egle.
Chapter 4 Macro Processors
Introduction to Classes and Objects
Algorithm for One-pass Macro Processor
by Richard P. Paul, 2nd edition, 2000.
Processor Fundamentals
A Simple Two-Pass Assembler
Chapter 1 Computer architecture Languages: machine, assembly, high
Chapter 6 Programming the basic computer
General Computer Science for Engineers CISC 106 Lecture 03
UNIT – IV MACRO PROCESSORS
An introduction to systems programming
CHAP 4 MACRO PROCESSORS.
Presentation transcript:

CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 11–Macro-Processors

2 Chapter 4 Macro Processors Source Code (with macro) Macro Processor Expanded Code Compiler or Assembler obj A program without Macro definitions

Introduction »A macro instruction (abbreviated to macro) is simply a notational convenience for the programmer. »A macro represents a commonly used group of statements in the source programming language »Expanding a macro –Replace each macro instruction with the corresponding group of source language statements

»E.g. –On SIC/XE requires a sequence of seven instructions to save the contents of all registers Write one statement like SAVERGS »A macroprocessor is not directly related to the architecture of the computer on which it is to run »Macro processors can also be used with high-level programming languages, OS command languages, etc.

5 4.1 Basic Macro Processor Functions Macro Definition and Expansion »Fig. 4.1 shows an example of a SIC/XE program using macro instructions. –RDBUFF and WRBUFF as user defined macronames –MACRO and MEND as keywords –Parameters of the macro instruction, each parameter begins with the character &. –Macro invocation statement and the arguments to be used in expanding the macro. »Fig. 4.2 shows the output that would be generated.

6 Declaring Macros - Fig. 4.1

7 Declaring Macros - Fig. 4.1 (Cont’d)

8 Macro Invocation – Fig 4.1

9 Expanded program– Fig 4.2

10 Expanded program– Fig 4.2 – (Cont’d)

11 Expanded program– Fig 4.2 – (Cont’d)

Basic Macro Processor Functions »Macro invocations and subroutine calls are different »Note also that the macro instructions have been written so that the body of the macro contains no label –Why? Leading to the use of relative addressing at the source statement level Only be acceptable for short jumps If labels were allowed, the multiple expansions of macros will results in multiple label declarations and hence errors.

13 Source STRG MACRO STADATA1 STBDATA2 STXDATA3 MEND. STRG. STRG. Expanded source. STADATA1 STBDATA2 STXDATA3. STADATA1 STBDATA2 STXDATA3. { {

Macro Processor Algorithm and Data Structures »Two-pass macro processor –All macro definitions are processed during the first pass. –All macro invocation statements are expanded during the second pass. –Two-pass macro processor would not allow the body of one macro instruction to contain definitions of other macros. »Such definitions of macros by other macros Fig. 4.3

15

16

Macro Processor Algorithm and Data Structures »A one-pass macro processor that can alternate between macro definition and macro expansion. –The definition of a macro must appear in the source program before any statements that invoke that macro. –Inconvenience of the programmer. –Macro definitions are stored in DEFTAB –Comment lines are not entered the DEFTAB.

Macro Processor Algorithm and Data Structures –The macro names are entered into NAMTAB, NAMTAB contains two pointers to the beginning and the end of the definition in DEFTAB –The third data structure is an argument table ARGTAB, which is used during the expansion of macro invocations. –The arguments are stored in ARGTAB according to their position in the argument list.

Macro Processor Algorithm and Data Structures »Fig. 4.4 shows positions of the contents of these tables during the processing. –Parameter &INDEV -> Argument ?1 –Parameter &BUFADR -> Argument ?2 –When the ?n notation is recognized in a line form DEFTAB, a simple indexing operation supplies the proper argument form ARGTAB.

20

Macro Processor Algorithm and Data Structures »The macro processor algorithm itself is presented in Fig –The procedure PROCESSING –The procedure DEFINE Called when the beginning of a macro definition is recognized, makes the appropriate entries in DEFTAB and NAMTAB. –The procedure EXPAND Called to set up the argument values in ARGTAB and expand a macro invocation statement. –The procedure GETLINE Called at several points in the algorithm, gets the next line to be processed. –EXPANDING is set to TRUE or FALSE.

22

23

24

Macro Processor Algorithm and Data Structures »To solve the problem is Fig. 4.3, our DEFINE procedure maintains a counter named LEVEL. –MACRO directive is read, the value of LEVEL is inc. by 1. –MEND directive is read, the value of LEVEL is dec. by 1.

4.2 Machine-Independent Macro Processor Features »4.2.1 Concatenation of Macro Parameters (Canceled) »4.2.2 Generation of Unique Labels (Canceled) »4.2.3 Conditional Macro Expansion (Canceled) »Keyword Macro Parameters

Keyword Macro Parameters »Positional parameters –Parameters and arguments were associated with each other according to their positions in the macro prototype and the macro invocation statements. –A certain macro instruction GENER has 10 possible parameters. Consecutive commas is necessary for a null argument GENER MACRO &1, &2, &type, …, &channel, &10 GENER,, DIRECT,,,,,, 3

Keyword Macro Parameters »Keyword parameters –Each argument value is written with a keyword that names the corresponding parameter. –Arguments may appear in any order. GENERTYPE=DIRECT, CHANNEL=3 parameter=argument –Fig shows a version of the RDBUFF using keyword.

29

30

31

Macro Processor Design Options Recursive Macro Expansion »In Fig. 4.3 we presented an example of the definition of one macro instruction by another. »Fig. 4.11(a) shows an example - Dealt with the invocation of one macro by another. »The purpose of RDCHAR Fig. 4.11(b) is to read one character from a specified device into register A, taking care of the necessary test-and-wait loop.

33

34

»Recursive Macro Expansion Applying Algorithm of Fig. 4.5: –The processing would proceed normally until line 50, which contains a statement invoking RDCHAR –In addition, the argument from the original macro invocation (RDBUFF) would be lost because the values in ARGTAB were overwritten with the arguments from the invocation of RDCHAR »Solution: –These problems are not difficult to solve if the macro processor is begin written in a programming language that allows recursive call

Recursive Macro Expansion »Fig. 4.11(c), applied to the macro invocation statement RDBUFFBUFFER, LENGTH, F1 »The procedure EXPAND would be called when the macro was recognized. »The arguments from the macro invocation would be entered into ARGTAB as follows:

Recursive Macro Expansion »The Boolean variable EXPANDING would be set to TRUE, and expansion of the macro invocation statement would be begin. »The processing would proceed normally until line 50, which contains a statement invoking RDCHAR. At that point, PROCESSLINE would call EXPAND again. »This time, ARGTAB would look like

Recursive Macro Expansion »At the end of this expansion, however, a problem would appear. When the end of the definition of RDCHAR was recognized, EXPANDING would be set to FALSE. »Thus the macro processor would “forget” that it had been in middle of expanding a macro when it encountered the RDCHAR statement. »Use a Stack to save ARGTAB. »Use a counter to identify the expansion level.