What is the difference between Macro-Processors and Pre-Processors?


Many assembly languages support a “macro” facility whereby a macro statement will translate into a sequence of assembly language statements and possibly other macro statements before being translated into a machine program. Therefore, a macro facility is a text replacement capability.

It can illustrate the utility of macros, consider a situation in which a machine does not have a single machine or assembly language statement that adds the contents of one memory address to another as hypothetical assembly instruction ADD X, Y. Instead, suppose the machine has an instruction LOAD, which moves a datum from memory to a register, an instruction ADD which adds the contents of a memory address to that of a register, and an instruction STORE, which moves data from register to memory.

By using these instructions, it can create with a macro definition, a “two-address add” instruction as follows −

ADD2    X, Y
ADD     X

The first statement gives the name ADD2 to the macro and defines its dummy arguments, known as the formal parameters X and Y.

The next three statement defines the macro that is, they give its translation. It can assume that the machine has only one register, so there is no question of what registers LOAD and STORE refers to. It can use ADD2 as an ordinary assembly language operation code.


Pre-Processor is a program that processes the source program before it passes through the compiler. It operates under the control of what is known as pre-processor command lines or directives. Pre-processor directives are located in the source code before the mainline. Pre-processor gives input to the compilers. It can perform the following functions which are as follows −

  • Macro-Processing − A preprocessor can enable a user to define macros that are shorthand for higher constructs.

  • File Inclusion − A pre-processor can include header files into the program LEX. For example, the C pre-processor generates the contents of the file <global.h> to restore the statement #include<global.h> when it processes a file including this statement.

  • Rational Pre-Processors − These processors augment earlier language with an additional current flow of control and data-structuring facilities. For example, such a pre-processor can support the user with built-in macros for constructs like while statements or if statements, where none exist in the programming language itself.

  • Language extensions − These processors try to insert capabilities into the language. For example, the language SQL is a database query language installed in C. Statements starting with # are taken by the pre-processor to be database access statements, independent to C, and are translated into procedure calls in routines that implement the database access.

Updated on: 23-Oct-2021

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started