Preview

4.1basic Macro Processor Functions

Good Essays
Open Document
Open Document
693 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
4.1basic Macro Processor Functions
4.1Basic macro processor functions

Introduction
A macro instruction (abbr. macro) is a notational convenience for the programmer. 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.

• This is called expanding the macros.
2

1

Introduction (cont’d)
The mostly common use of macro processors is in assembler language programming. The design of a macro processor is not directly related to the architecture of the computer on which it is to run.

3

Macro definition
Two new assembler directives are used in macro definition. macro_name MACRO ¶1, ¶2 ...... MEND

• •

The macro name and parameters define a pattern or prototype for the macro instructions used by the programmer. Following the MACRO directive are the statements that make up the body of the macro definition.

4

2

Macro invocation
A macro invocation statement gives the name of the macro instruction being invoked and the arguments to be used in expanding the macro. The process of macro invocation and subroutine call are quite different.

• •

The statements that form the expansion of a macro are generated (and assembled) each time the macro in invoked. Statements in a subroutine appear only once, regardless of how many times the subroutine is called.

5

A macro definition

Use of Macro

Macro invocation

3

Macro expansion
The macro instruction definitions are deleted since they are no longer needed after the macros are expanded. Each macro invocation statement is expanded into the statements that form the body of the macro, with the arguments from the macro invocation substituted for the parameters in the macro prototype.



Can a label appear in the body of a macro? Yes

7

Macro expansion (cont’d)
After macro processing, the expanded file can be used as input to the assembler.
Macro

You May Also Find These Documents Helpful

  • Satisfactory Essays

    3. When a module is executing, what happens when the end of the module is reached?…

    • 765 Words
    • 5 Pages
    Satisfactory Essays
  • Better Essays

    Nt1310 Unit 4

    • 3614 Words
    • 15 Pages

    If the following program (myprog) is run from the command line as myprog 1 2 3, What would be the output?…

    • 3614 Words
    • 15 Pages
    Better Essays
  • Satisfactory Essays

    SD1230 Lab 1

    • 239 Words
    • 2 Pages

    1. What is an instruction? – A sequence of bits understood by the processor to signal a certain action…

    • 239 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Chapter 20 lab

    • 284 Words
    • 2 Pages

    4. What does dnl stand for in the m4 macro language; what are dnl commands used for?…

    • 284 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    Nt1310 Unit 3 Quiz

    • 6337 Words
    • 26 Pages

    What is the primary purpose of the __P() macro? Choice 1 The __P() macro has no function, and merely obfuscates library function declarat ions. It should be removed from further releases of the C library. Choice 2 The __P() macro provides forward compatibility for C++ compilers, which do not r ecognize Standard C prototypes. Choice 3 Identifiers that begin with two underscores are reserved for C library implement ations. It is impossible to determine the purpose of the macro from the context given. Choice 4 The __P() macro provides backward compatibility for K&R C compilers, which do no t recognize Standard C prototypes. Choice 5 The __P() macro serves primarily to differentiate library functions from applica tion-specific functions. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /*question number 68*/ Which one of the following is NOT a valid identifier? Choice 1 __ident Choice 2 auto [Ans] Choice 3 bigNumber Choice 4 g42277 Choice 5 peaceful_in_space - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /*question number 69*/ /* Read an arbitrarily long string. */ Code: int read_long_string (const char ** const buf) { char * p = NULL; const char * fwd = NULL; size_t len = 0; assert(buf); do { p = realloc(p, len += 256); if (!p) return 0; if (!fwd) fwd = p; else fwd = strchr(p, '\0'); } while (fgets(fwd, 256, stdin)); *buf =…

    • 6337 Words
    • 26 Pages
    Good Essays
  • Good Essays

    Unit 59 Assignment 3

    • 645 Words
    • 3 Pages

    The process of how the subroutine works within an operating environment is as follows. While the main part of the program is running, there will be a call command sent to the CPU to tell it to stop wherever the program is at, store the W, Z and status along with where in the main program the CPU is at in the stack. Then the main program is cleared from memory and the subroutine is loaded for the CPU to start processing the code. Once the subroutine has finished, the subroutine code is deleted from memory and the CPU will load up the main program back on and will retrieve from stack the stored information (W, Z and status) which will allow the CPU know exactly where it needs to start from.…

    • 645 Words
    • 3 Pages
    Good Essays
  • Powerful Essays

    Comp3652 Unit 2 Assignment

    • 1090 Words
    • 5 Pages

    valued arguments. The syntax of a call should look like the usual infix syntax (e.g. as used in C,…

    • 1090 Words
    • 5 Pages
    Powerful Essays
  • Powerful Essays

    Nt1310 Unit 1

    • 4209 Words
    • 17 Pages

    If two steps are indented at the same level, the uppermost statement is executed first. ans)All of the above…

    • 4209 Words
    • 17 Pages
    Powerful Essays
  • Powerful Essays

    En1320 Unit 1 Research Paper 1

    • 27742 Words
    • 111 Pages

    instructions to load the registers of the processor with data from a central memory and to…

    • 27742 Words
    • 111 Pages
    Powerful Essays
  • Satisfactory Essays

    Pt1420 Assignment

    • 1058 Words
    • 5 Pages

    1) Initialization: the variable is initialized 2) Test: the loop tests the variable by comparing it to the maximum value 3) Increment: to increase the value during each iteration the loop increments the counter variable by adding 1 to it.…

    • 1058 Words
    • 5 Pages
    Satisfactory Essays
  • Satisfactory Essays

    linux

    • 456 Words
    • 2 Pages

    The dnl command, which stands for delete to new line, instructs the compiler to ignore anything on a line following the dnl. It is used to set off…

    • 456 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Intro the Programming

    • 386 Words
    • 5 Pages

    When you call a(n) ______, it simply executes the statement it contains and then terminates.…

    • 386 Words
    • 5 Pages
    Satisfactory Essays
  • Good Essays

    Itq Coursework

    • 6612 Words
    • 27 Pages

    In some programmes like microsoft office you can automate frequently used tasks by creating macros. A macro is a series of commands and instructions that you group together as a single command to accomplish a task automatically. Macros are used to speed up routine editing and formatting, to combine multiple commands, to make an option in a dialog box more accessible, to automate a complex series of tasks.…

    • 6612 Words
    • 27 Pages
    Good Essays
  • Good Essays

    Operating System

    • 1099 Words
    • 5 Pages

    Answer: d. It redirects the output of one command to the input of another command.…

    • 1099 Words
    • 5 Pages
    Good Essays
  • Good Essays

    Reusability of Code

    • 511 Words
    • 3 Pages

    The earliest programming languages were procedural, meaning a program was made of one or more procedures. A procedure is simply a module or function that performs a specific task such as gathering input from the user, performing calculations, reading or writing files, displaying output, and so on. The programs that you have written so far have been procedural in nature. The steps a program must perform to reach the desired outcome. Procedure is an independent entity and a sequence of instructions that are grouped together. In procedural programming, a task is broken down into assortment of variables and subroutines. In OPP, a task is broken down into objects which summarize the data and execution. In a procedural approach, the entirely called variable is termed as a trait of the object. The idea is to encapsulate data and a…

    • 511 Words
    • 3 Pages
    Good Essays