Open In App

Difference between Macro and Procedure

Last Updated : 07 Jun, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Assembly language is a common intermediate level programming language which is used for microprocessor programming. This macro and procedure are two concepts in assembly by which modular programming is implemented. So now let’s understand how macro and procedure are different from each other. 

1. Macro : 
Macro is a set of instruction and the programmer can use it anywhere in the program by using its name. It is mainly used to achieve modular programming. So same set of instructions can be used multiple times when ever required by the help of macro. Wherever macro’s identifier is used, it is replaced by the actual defined instructions during compilation thereby no calling and return occurs. 

Syntax of macro : 

%macro macro_name number_of_parameters
<macro body>
%endmacro

2. Procedure : 
Procedures are also like macro, but they are used for large set of instruction when macro is useful for small set of instructions. It contains a set of instructions which performs a specific task. It contains three main parts i.e Procedure name to identify the procedure, procedure body which contains set of instructions, and RET statement which denotes return statement. Unlike macros, procedures follow call-return method thereby achieving true modularity.

Syntax of Procedure : 

procedure_name :
procedure body
 ….......................
RET

To call a procedure 
 

CALL procedure_name

After execution of procedure control passes to the calling procedure using RET statement. 

Difference between Macro and Procedure : 

 

S.No. MACRO PROCEDURE
01. Macro definition contains a set of instruction to support modular programming. Procedure contains a set of instructions which can be called repetitively which can perform a specific task.
02. It is used for small set of instructions mostly less than ten instructions. It is used for large set of instructions mostly more than ten instructions.
03. In case of macro memory requirement is high. In case of procedure memory requirement is less.
04. CALL and RET instruction/statements are not required in macro. CALL and RET instruction/statements are required in procedure.
05. Assembler directive MACRO is used to define macro and assembler directive ENDM is used to indicate the body is over. Assembler directive PROC is used to define procedure and assembler directive ENDP is used to indicate the body is over.
06. Execution time of macro is less as it executes faster than procedure. Execution time of procedures is high as it executes slower than macro.
07. Here machine code is created multiple times as each time machine code is generated when macro is called. Here machine code is created only once, it is generated only once when the procedure is defined.
08. In a macro parameter is passed as part of statement that calls macro. In a procedure parameters are passed in registers and memory locations of stack.
09. Overhead time does not take place as there is no calling and returning. Overhead time takes place during calling procedure and returning control to calling program.

 


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads