📜  宏和过程之间的区别

📅  最后修改于: 2021-08-27 04:44:26             🧑  作者: Mango

汇编语言是用于微处理器编程的通用中间级编程语言。该宏和过程是汇编中用于实现模块化编程的两个概念。现在,让我们了解一下宏和过程之间的区别。

1.宏:
宏是一组指令,程序员可以使用宏的名称在程序中的任何位置使用它。它主要用于实现模块化编程。因此,在宏的帮助下,同一组指令可以多次使用。无论在何处使用宏的标识符,在编译过程中都将其替换为实际定义的指令,从而不会发生调用和返回。

宏的语法:

%macro macro_name number_of_parameters

%endmacro

2.程序:
过程也类似于宏,但是当宏对少量指令集有用时,它们将用于大量指令集。它包含一组执行特定任务的指令。它包含三个主要部分,即用于标识过程的过程名称,包含指令集的过程主体以及表示return语句的RET语句。与宏不同,过程遵循调用返回方法,从而实现了真正的模块化。

程序语法:

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

调用程序

CALL procedure_name

在执行过程后,控制将使用RET语句传递给调用过程。

宏和过程之间的区别:

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 than 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.