An introduction to systems programming

Slides:



Advertisements
Similar presentations
Question Bank. Explain the syntax of if else statement? Define Union Define global and local variables with example Concept of recursion with example.
Advertisements

COP 3402 Systems Programming
The University of Adelaide, School of Computer Science
1 Chapter 8: Code Generation. 2 Generating Instructions from Three-address Code Example: D = (A*B)+C =* A B T1 =+ T1 C T2 = T2 D.
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.
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.
CPSC Compiler Tutorial 9 Review of Compiler.
Chih-Hung Wang Chapter 2: Assembler (Part-1) 參考書目 Leland L. Beck, System Software: An Introduction to Systems Programming (3rd), Addison-Wesley, 1997.
1 Chapter 4 Macro Processors Source Code (with macro) Macro Processor Expanded Code Compiler or Assembler obj.
Chapter 4 Macro Processors
Describing Syntax and Semantics
1. 2 FUNCTION INLINE FUNCTION DIFFERENCE BETWEEN FUNCTION AND INLINE FUNCTION CONCLUSION 3.
Inline Function. 2 Expanded in a line when it is invoked Ie compiler replace the function call with function code To make a function inline the function.
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.
Chapter 6: Function. Scope of Variable A scope is a region of the program and broadly speaking there are three places, where variables can be declared:
5.3 Machine-Independent Compiler Features
Methods Chapter 6. 2 Program Modules in Java What we call "functions" in C++ are called "methods" in Java Purpose Reuse code Modularize the program This.
Chapter 10: Compilers and Language Translation Invitation to Computer Science, Java Version, Third Edition.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. C How To Program - 4th edition Deitels Class 05 University.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Functions.
1 Homework / Exam Finish up K&R Chapters 3 & 4 Starting K&R Chapter 5 Next Class HW4 due next class Go over HW3 solutions.
CSC 3210 Computer Organization and Programming Chapter 1 THE COMPUTER D.M. Rasanjalee Himali.
5-1 Chapter 5 - Languages and the Machine Department of Information Technology, Radford University ITEC 352 Computer Organization Principles of Computer.
Assembly Language Macros Most assemblers include support for macros. The term macro refers to a word that stands for an entire group of instructions. Macro.
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)
5-1 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Principles.
1 Assemblers System Programming by Leland L. Beck Chapter 2.
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.
FOUNDATION IN INFORMATION TECHNOLOGY (CS-T-101) TOPIC : INFORMATION SYSTEM – SOFTWARE.
Macro Processors.
Chapter 12: Programming in the Large By: Suraya Alias 1-1.
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.
CPS 4150 Computer Organization Chapter 2-2 Fall 2006 Ching-Song Don Wei.
COMPILERS CLASS IV Er. Vikram Dhiman M.tech NIT jalandhar.
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture 1 Ahmed Ezzat.
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 11–Macro-Processors.
Unit 10 Code Reuse. Key Concepts Abstraction Header files Implementation files Storage classes Exit function Conditional compilation Command-line arguments.
Macro Processor Design Options Recursive Macro Expansion General-Purpose Macro Processors Macro Processing within Language Translators.
BIL 104E Introduction to Scientific and Engineering Computing Lecture 4.
Methods Chapter 6.
Programming Fundamentals Lecture #7 Functions
MACRO Processors CSCI/CMPE 3334 David Egle.
Chapter 4 Macro Processors
Introduction to Classes and Objects
Algorithm for One-pass Macro Processor
Translators & Types of Languages
System Programming by Leland L. Beck Chapter 2
Assemblers CSCI/CMPE 3334 David Egle.
Chapter 1 Computer architecture Languages: machine, assembly, high
Chapter 6 Programming the basic computer
The structure of programming
UNIT – IV MACRO PROCESSORS
An introduction to systems programming
Thinking procedurally
CHAP 4 MACRO PROCESSORS.
SPL – PS1 Introduction to C++.
Procedures & Macros Introduction Syntax Difference.
Presentation transcript:

An introduction to systems programming Macro Processors Chapter 4 System Software An introduction to systems programming Leland L. Beck

Introduction Concept A macro instruction is a notational convenience for the programmer It allows the programmer to write shorthand version of a program (module programming) The macro processor replaces each macro invocation with the corresponding sequence of statements (expanding)

Macro Processor Recognize macro definitions Save the macro definition Recognize macro calls Expand macro calls Source Code (with macro) Macro Processor Expanded Code Compiler or Assembler obj

Macro Definition copy code parameter substitution conditional macro expansion macro instruction defining macros

{ { Copy code -- Example Source STRG MACRO STA DATA1 STB DATA2 STX DATA3 MEND . STRG Expanded source . STA DATA1 STB DATA2 STX DATA3 { {

Macro vs. Subroutine Macro Subroutine the statement of expansion are generated each time the macro are invoked Subroutine the statement in a subroutine appears only once

Parameter Substitution -- Example Source STRG MACRO &a1, &a2, &a3 STA &a1 STB &a2 STX &a3 MEND . STRG DATA1, DATA2, DATA3 STRG DATA4, DATA5, DATA6 Expanded souce . STA DATA1 STB DATA2 STX DATA3 STA DATA4 STB DATA5 STX DATA6 { {

Parameter Substitution Dummy arguments Positional argument STRG DATA1, DATA2, DATA3 GENER ,,DIRECT,,,,,,3 Keyword argument STRG &a3=DATA1, &a2=DATA2, &a1=DATA3 GENER TYPE=DIRECT, CHANNEL=3 Example: Fig. 4.1, Fig. 4.2 Labels are avoided in macro definition

One-Pass Macro Processor Prerequisite every macro must be defined before it is called Sub-procedures macro definition: DEFINE macro invocation: EXPAND NAMTAB DEFINE EXPAND MACRO CALL DEFTAB PROCESSLINE ARGTAB

Data Structures -- Global Variables DEFTAB NAMTAB ARGTAB EXPANDING

Nested Macros Definition Macro definition within macros process macro definition during expansion time Example 4.3

Figure 4.3 (b)

One-Pass Macro Processor That Allows Nested Macro Definition Sub-procedures macro definition: DEFINE macro invocation: EXPAND EXPAND may invoke DEFINE when encounter macro definition DEFTAB NAMTAB ARGTAB Expanding DEFINE EXPAND MACRO CALL PROCESSLINE MACRO Definition

1-Pass Macro Processor

Comparison of Macro Processors Design Single pass every macro must be defined before it is called one-pass processor can alternate between macro definition and macro expansion nested macro definitions may be allowed but nested calls are not Two pass algorithm Pass1: Recognize macro definitions Pass2: Recognize macro calls nested macro definitions are not allowed

Concatenation of Macro Parameters Pre-concatenation LDA X&ID1 Post-concatenation LDA X&ID1 Example: Figure 4.6

Generation of Unique Labels Example JEQ *-3 inconvenient, error-prone, difficult to read Example Figure 4.7 $LOOP TD =X’&INDEV’ 1st call: $AALOOP TD =X’F1’ 2nd call: $ABLOOP TD =X’F1’

RDBUFF F1, BUFFER, LENGTH

Conditional Macro Expansion Macro-time conditional statements Example: Figure 4.8 IF-ELSE-ENDIF Macro-time variables any symbol that begins with the character & and that is not a macro parameter macro-time variables are initialized to 0 macro-time variables can be changed with their values using SET &EORCK SET 1

RDBUFF F3, BUF, RECL, 04, 2048 RDBUFF 0E, BUFFER, LENGTH, , 80

RDBUFF F1, BUFF, RLENG, 04

Conditional Macro Expansion (Cont.) Macro-time looping statement Example: Figure 4.9 WHILE-ENDW Macro processor function %NITEMS: THE NUMBER OF MEMBERS IN AN ARGUMENT LIST

Nested Macro Invocations Macro invocations within macros process macro invocation during expansion time Recursive macro expansion Example: Figure 4.11 Problems: ARGTAB EXPANDING Solution Recursive call While loop with stack

ARGTAB DEFINE EXPAND PROCESSLINE DEFTAB NAMTAB MACRO Definition GETLINE PROCESSLINE Macro Invocation EXPAND ARGTAB

1-Pass Macro Processor

Allowing Nested Macro Invocation

Macro-Assembler Advantage Disadvantage reduce 1 pass share same data structure Disadvantage more complex

Process machine instruction Pass 1 READ Search (Pseudo-Op Table) Pass 2 R Type? Search NAMTAB (Macro Name Table) MACRO Define Process pseudo-ops Search (Machine Op Table) R R MACRO Expand Process machine instruction R R

General Purpose Macro Processor ELENA Software: Practice and Experience, Vol. 14, pp. 519-531, Jun. 1984 Macro definition header: a sequence of keywords and parameter markers (%) at least one of the first two tokens in a macro header must be a keyword, not a parameter marker body: the character & identifies a local label macro time instruction (.SET, .IF .JUMP, .E) macro time variables or labels (.)

ELENA (cont.) Macro invocation There is no single token that constitutes the macro “name” Constructing an index of all macro headers according to the keywords in the first two tokens of the header Example DEFINITION: ADD %1 TO %2 ADD %1 TO THE FIRST ELEMENT OF %2 INVOCATION: DISPLAY TABLE DISPLAY %1 %1 TABLE