MACROS Suthida Chaichomchuen Purposes  To simplify and reduce the amount of repetitive coding.  To reduce errors caused by repetitive.

Slides:



Advertisements
Similar presentations
IF statement (i) Single statement. IF ( logical expression ) statement Example: read(*,*) a if (a. lt. 0) a = -a write(*,*) a Or read(*,*) a if (a < 0)
Advertisements

Linux Shell Script. Shell script The first line is used to specify shell program #!/bin/sh Variables variable=“text” variable=0 variable=`program arguments`
Macro simple idea of textual substitution useful when you need a group of instructions or directives frequently.
Macro Processor.
Macro Processors (MP) Macro: Macro Processors (MP): Examples:
Lecture 2 Introduction to C Programming
Introduction to C Programming
Introduction to C Programming
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#4)
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 17 - The Preprocessor Outline 17.1Introduction 17.2The #include Preprocessor Directive 17.3The.
Introduction to C Programming Overview of C Hello World program Unix environment C programming basics.
Chapter 4 Macro Processors
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 13 - The Preprocessor Outline 13.1Introduction.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 13 - The Preprocessor Outline 13.1Introduction 13.2The #include Preprocessor Directive 13.3The.
Introduction to C Programming
Shell Programming 1. Understanding Unix shell programming language: A. It has features of high-level languages. B. Convenient to do the programming. C.
Programming the Microprocessor A Course in Microprocessor Electrical Engineering Dept. University of Indonesia.
C How to Program, 6/e © by Pearson Education, Inc. All Rights Reserved.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 19 - The Preprocessor Outline 19.1 Introduction 19.2 The #include Preprocessor Directive 19.3.
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#7)
CoE3DJ4 Digital Systems Design
Bash shell programming Part II – Control statements Deniz Savas and Michael Griffiths November 2005 Corporate Information and Computing Services The University.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 251 Introduction to Computer Organization.
The Structure of a C++ Program. Outline 1. Separate Compilation 2. The # Preprocessor 3. Declarations and Definitions 4. Organizing Decls & Defs into.
Programming With C.
Chapter 13 Programming in the Large Dr. Jiung-yao Huang Dept. Comm. Eng. Nat. Chung Cheng Univ. TA: 鄭筱親 陳昱豪.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
COMPUTER PROGRAMMING. A Typical C++ Environment Phases of C++ Programs: 1- Edit 2- Preprocess 3- Compile 4- Link 5- Load 6- Execute Loader Primary Memory.
Fundamentals of C and C++ Programming. EEL 3801 – Lotzi Bölöni Sub-Topics  Basic Program Structure  Variables - Types and Declarations  Basic Program.
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.
Shells. Variables MESSAGE="HELLO WORLD" echo $MESSAGE MESSAGE="HELLO WORLD $LOGNAME" echo $MESSAGE MESSAGE="HELLO WORLD $USER" echo $MESSAGE.
Basic Program Construction
 2003 Prentice Hall, Inc. All rights reserved. 1 IS 0020 Program Design and Software Tools Preprocessing Lecture 12 April 7, 2005.
(A Very Short) Introduction to Shell Scripts CSCI N321 – System and Network Administration Copyright © 2000, 2003 by Scott Orr and the Trustees of Indiana.
Chapter 8 Advanced Programming Applications Objectives: Linking separate object files together Creating and using an object code library Predicting the.
©Colin Jamison 2004 Shell scripting in Linux Colin Jamison.
CT215: Assembly Language Programming Chapter 10: Macros (c) Pearson Education, All rights reserved. You may modify and copy this slide show for your.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 10: Structures and Macros (c) Pearson Education, All rights reserved. You.
 2003 Prentice Hall, Inc. All rights reserved. 1 IS 0020 Program Design and Software Tools Preprocessor Midterm Review Lecture 7 Feb 17, 2004.
Recap……Last Time [Variables, Data Types and Constants]
Assembly Language programming
In Class Program Write, assemble and test a program: –Use the DB directive to define the following list of numbers and name it array: 31h, 32h, 33h, 34h.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
THE PREPROCESSOR
The Preprocessor Directives Introduction Preprocessing – Occurs before program compiled Inclusion of external files Definition of symbolic constants.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 13 - The Preprocessor Outline 13.1Introduction 13.2The #include Preprocessor Directive 13.3The.
© Oxford University Press All rights reserved. CHAPTER 10 THE PREPROCESSOR DIRECTIVE.
Announcements Assignment 1 due Wednesday at 11:59PM Quiz 1 on Thursday 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.
Macros Covers chapter 8, pages 300 – 314. Run-time vs. Assemble-time Almost everything but the main body of an assembly-language program deals with assemble-time.
Assembly Language Lecture 2. Lecture Outline Program Structure Memory models Data Segment Stack Segment Code Segment Input and Output Instructions INT.
1 Lecture 8 Shell Programming – Control Constructs COP 3353 Introduction to UNIX.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#7) By Dr. Syed Noman.
The full name of PERL is Practical extraction and report language. It is similar to shell script and lot easier & powerful language. Perl is free to download.
Assembly Language programming
Chapter 2 - Introduction to C Programming
INC 161 , CPE 100 Computer Programming
Chapter 13 - The Preprocessor
MIPS assembly syntax Comments
Programming Fundamentals Lecture #7 Functions
Chapter 2 - Introduction to C Programming
MACRO Processors CSCI/CMPE 3334 David Egle.
Chapter 4 Macro Processors
Register Variables Declaring a variable as a "register" variable is an advisory to the compiler to keep the normal location of the variable in a register,
UNIT – IV MACRO PROCESSORS
Introduction to C Programming
Chapter 5 Selection Statements
Presentation transcript:

MACROS Suthida Chaichomchuen

Purposes  To simplify and reduce the amount of repetitive coding.  To reduce errors caused by repetitive coding.  To make an assembly program more readable.

Functions that implemented by macro  Input/Output operation that load register and perform interrupt  Conversions of ASCII and binary data  Multiword arithmetic operation  String-handling routines

Format of macro definition macronameMACRO [parameter list] [instructions] ENDM ;Define macro ;Body of macro ;End of macro

Simple macro definitions INITZMACRO;Define macro MOV Body MOV DS,AX ; of MOV ES,AX ; macro definition ENDM;End of macro

Simple macro definitions FINISHMACRO;Define macro MOV AX,4C00H ;Body of INT 21H ;macro definition ENDM;End of macro

Using parameter in Macros PROMPTMACROMESSAGE;dummy argument MOVAH,09H LEADX,MESSAGE INT 21H ENDM;End of macro

Using parameter in Macros MESSAGE2DB‘Enter the date as mm/dd/yy’ PROMPTMESSAGE2

Macro Comments PROMPTMACROMESSAGE ; This macro permits a display of messages MOVAH,09H;Request display LEADX,MESSAGE;prompt INT 21H ENDM

.LALL : List all - including the leading period. .SALL : suppress all - not list any source code of a macro expansion .XALL : default - list only the instructions that generate object code. Macro Listing directive

The LOCAL directive Used for define the data items and instruction labels within the macro definition itself. LOCALdummy-1, dummy-2,.. ;One or more dummy argument

Including Macros from a library Programs can use any of the cataloged macros by use an INCLUDE directive like this. INCLUDEPath and file name Example:INCLUDEF:\MACRO.LBY

The PURGE directive Use to delete the unwanted macros from the current assembly. PURGEMacro names Example:PURGEPROMPT, DIVIDE

Concatenation Used the ampersand (&) character tells the assembler to join text or symbols. STRMOVEMACROTAG REPMOVS&TAG ENDM

 REPT : Repeat Directive  IRP : Indefinite Repeat Directive  IRPC : Indefinite Repeat Character Directive Repetition directive

Repeat a block of statements up to ENDM according to the number of times in the expression entry. REPTexpression Repetition directive : REPT

REPT4 DECSI ENDM REPT : Examples

N = 0 REPT5 N = N + 1 DBN ENDM REPT : Examples

Repeat a block of instructions up to ENDM. IRPdummy, Repetition directive : IRP

IRPN, DBN ENDM IRP : Examples

IRPREG, PUSHREG ENDM IRP : Examples

Repeat a block of statements up to ENDM. IRPCdummy, string Repetition directive : IRPC

IRPCN, DWN ENDM IRPC : Examples

IFxx(condition)... ELSE(optional)... ENDIF(end of IF) Conditional directives

 IF : If the expression evaluates to a nonzero value, assemble the statements within the conditional block.  IFE : If the expression evaluates to a zero, assemble the statements within the conditional block.

Conditional directives  IF1 (no expression) : If processing pass 1, act on the statements in the conditional block.  IF2 (no expression) : If processing pass 2, act on the statements in the conditional block.

Conditional directives  IFDEF symbol : If the symbol is defined in the program or is declared as EXTRN, process the statements in the conditional block.  IFNDEF symbol : If the symbol is not defined or is not declared as EXTRN, process the statements in the conditional block.

Conditional directives  IFB : If the argument is blank, process the statements in the conditional block. The argument requires angle brackets.  IFNB : If the argument is not blank, process the statements in the conditional block. The argument requires angle brackets.

Conditional directives  IFIDN, : If the argument-1 string is identical to the argument-2 string, process the statements in the conditional block. The argument require angle brackets.

Conditional directives  IFDIF, : If the argument-1 string is different to the argument-2 string, process the statements in the conditional block. The argument require angle brackets.

Conditional directives  IF and IFE can use the relational operators : –EQ (equal) –NE (not equal) –LT (less than) –LE (less than or equal) –GT (greater than) –GE (greater than or equal)

FINISHMACRORETCODE MOVAH, 3CH IFNB MOVAL, RETCODE ENDIF INT21H ENDM Examples

INT21MACROFUNCTION, DXADDRES MOVAH, FUNCTN IFNB MOVDX, OFFSET DXADDRES ENDIF INT21H ENDM Examples

IFxx[condition]...(invalid condition) EXITM... ENDIF EXITM directives

IFCNTR ; Macro expansion terminated EXITM ENDIF Using IF and IFDEF conditions

IFIDN, REPMOVSB... Using IFIDN condition

IFIDN, REPMOVSW... Using IFIDN condition