What is the Difference Between Macro and Procedure

The main difference between Macro and Procedure is that the Macro is used for a small number of instructions; less than ten instructions, but Procedure is used for a large number of instructions; higher than ten instructions. 

A microprocessor is a computer processor that performs the tasks of a Central Processing Unit (CPU) on a single integrated circuit (IC). It handles output devices and processes the instructions stored in its memory and provides the output. These processors consist of combinational as well as sequential digital circuits. Moreover, Assembly language is a programing language that helps to program the microprocessors. Overall, Macro and Procedure are two concepts in Microprocessor programming.

Key Areas Covered

1. What is Macro
-Definition, Functionality
2. What is Procedure
– Definition, Functionality
3. Difference Between Macro and Procedure
-Comparison of key differences

Key Terms

Assembly Language, Macro, Microprocessor, Procedure, Program

Difference Between Macro and Procedure - Comparison Summary

What is Macro

A macro is a set of instructions which has a name, and the programmer can use it anywhere in the program. The main objective of Macros is to achieve modular programming. Furthermore, a macro begins with the %macro directive and ends with the %endmacro directive. 

Difference Between Macro and ProcedureThe syntax of Macro is as follows.

%macro macro_name number_of_params

<macro body>

%endmacro

The macro_name helps to identify the macro and the number_of_params refers to the number parameters. Additionally,  it is possible to invoke the macro using the macro name with the required parameters. Therefore, if it is necessary to execute the same set of instructions multiple times, the programmer can write those instructions in a macro and use that in his program.

What is Procedure

Procedures are useful to make a large program easier to read, maintain and modify. Usually, a procedure consists of three main sections. Firstly, the procedure name that helps to identify the procedure. Secondly, the statements inside the body, which describes the task to perform. Finally, the return statement that denotes the return statement.

The syntax of Macro is as follows.

proc_name:

            procedure body

            …

            RET

Furthermore, some functions call a procedure using the CALL instruction. That instruction is as follows.

CALL procedure_name

Finally, after executing the procedure, the control passes to the calling procedure using RET instruction.

Difference Between Macro and Procedure

Definition

Macro is a sequence of instructions that are written within the macro definition to support modular programming. On the other hand, a procedure is a set of instructions that performs a specific task, and a programmer can call it repetitively. Thus, this is the fundamental difference between macro and procedure.

Number of Instructions

A macro is used for a small number of instructions; mostly, less than ten instructions, while a procedure is used for a large number of instructions; mostly, higher than ten instructions. Hence, this is the main difference between macro and procedure.

Memory Requirement

Besides, a macro requires more memory, whereas a procedure requires less memory.

CALL and RET

Moreover, the macro does not require CALL and RET instructions, while a procedure requires  CALL and RET instructions. 

Machine Code

In macro, the machine code is generated each time the macro is called. But, in the procedure, the machine code is generated only once. Hence, this is another difference between macro and procedure.

Passing Parameters

In macro, the parameters pass as a part of a statement that calls the macro. Whereas, in a procedure, the parameters are passed in registers and memory locations of the stack. Thus, this is also a difference between macro and procedure.

Overhead time

Also, a macro eliminates the overhead time to call the procedure and return the program, while a procedure requires more overhead time to call the procedure and return back to the calling procedure.

Execution Speed

Furthermore, a macro executes faster than a procedure.

Conclusion

In brief, assembly language is a common programming language used for microprocessor programming, and Macro and Procedure are two concepts in Assembly. The main difference between Macro and Procedure is that a macro is used for a small number of instructions; mostly, less than ten instructions, while the procedure is used for a large number of instructions; mostly, higher than ten instructions. 

References:

1.Tutorialspoint.com. “Assembly Macros.” Www.tutorialspoint.com, Available here.
2.Tutorialspoint.com. “Assembly Procedures.” Www.tutorialspoint.com, Available here.
3.“Macros in Microprocessor | Comparison of Procedure and Macro.” EEEGUIDE, 13 Aug. 2018, Available here.
4.Macros, Available here.
5.“Procedure Call and Return Instructions.” Procedure Call and Return Instructions (IA-32 Assembly Language Reference Manual), Available here.

Image Courtesy:

1.”assembly language” By Swtpc6800 en:User:Swtpc6800 Michael Holley – Own work (Public Domain) via Commons Wikimedia

About the Author: Lithmee

Lithmee holds a Bachelor of Science degree in Computer Systems Engineering and is reading for her Master’s degree in Computer Science. She is passionate about sharing her knowldge in the areas of programming, data science, and computer systems.

Leave a Reply